Skip to content
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

Merged
merged 3 commits into from
Nov 2, 2023

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented Oct 31, 2023

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.

@tgoyne tgoyne self-assigned this Oct 31, 2023
Copy link

coveralls-official bot commented Oct 31, 2023

Pull Request Test Coverage Report for Build github_pull_request_282307

  • 76 of 112 (67.86%) changed or added relevant lines in 9 files are covered.
  • 136 unchanged lines in 15 files lost coverage.
  • Overall coverage remained the same at 91.68%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/test_sync.cpp 4 5 80.0%
src/realm/sync/transform.cpp 58 66 87.88%
test/peer.hpp 2 29 6.9%
Files with Coverage Reduction New Missed Lines %
src/realm/sync/transform.cpp 1 63.48%
test/test_dictionary.cpp 1 99.85%
src/realm/sync/network/http.hpp 2 80.87%
src/realm/sync/network/websocket.cpp 2 75.15%
src/realm/table_view.cpp 2 94.18%
src/realm/uuid.cpp 2 97.06%
src/realm/sync/network/network.cpp 3 89.65%
src/realm/util/future.hpp 3 95.97%
test/peer.hpp 3 85.17%
src/realm/util/assert.hpp 4 87.1%
Totals Coverage Status
Change from base Build 1805: 0.0%
Covered Lines: 230608
Relevant Lines: 251537

💛 - 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.
Copy link
Collaborator

@danieltabacaru danieltabacaru left a 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.

Copy link
Contributor

@michael-wb michael-wb left a 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.

@tgoyne tgoyne merged commit 7698220 into master Nov 2, 2023
2 checks passed
@tgoyne tgoyne deleted the tg/transform branch November 2, 2023 16:38
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants