-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify sync::Transformer and eliminate the abstract interface #7099
Conversation
Pull Request Test Coverage Report for Build github_pull_request_282307
💛 - Coveralls |
transform.cpp uses the magic of templates to generate a very, very large number of functions, and many of them were unnecessarily extern. This resulted in the symbol table being over half of transform.o in Release builds. Making more of them private cuts the arm64 Release build from 250 KB to 128 KB.
Transformer objects used to have some local state which had to be stored between uses and had the implementation hidden in the cpp file. Neither of those are true any more, so the design doesn't make sense either. It can now just be a stack-allocated local created when needed rather than something which has to be stored and reused.
These were required prior to dangling links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I think there may be some value in holding state between transformations, but that requires some other changes (by making ChangesetIndex more flexible for example). Let's cross that bridge if/when we get there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - it's nice to clean up this code a bit.
https://github.com/realm/realm-sync/pull/3196 pulled TransformerImpl out of the anonymous namespace and made it extern. This innocent-looking change actually had a meaningful effect: a very, very large number of functions defined by composing templates were no longer inlined out of existence because static functions are inlined more aggressively than extern functions. Moving all of the helper functions back to the anonymous namespace results in transform.o halving in size due to better inlining.
While poking at this I noticed that Transformer's API didn't make any sense any more. It was designed to support Transformer objects holding state between transformations and to hide the implementation type entirely in the cpp file. Neither of these are done any more, so it was just very overcomplicated for no benefit.
This cuts ~150 KB off the obj-c dylib and makes the sync transform benchmark 5-10% faster, which doesn't seem big enough to be worth mentioning in the changelog.