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

RCORE-2223 reduce unnecessary table selections in replication #7899

Merged
merged 3 commits into from
Aug 6, 2024

Conversation

ironage
Copy link
Contributor

@ironage ironage commented Jul 19, 2024

This uses the idea in #7734 and takes it a bit further. Although mutations on embedded objects are now ignored, the selections on their tables still made it into the history. In the test download this leads to a history like this:

Select table: class_top
Create object: ObjKey(1)
Select table: class_top__meta
Select table: class_top
Select table: class_top__meta
Select table: class_top
Select table: class_top_embedded1
Select table: class_top
Select table: class_top_embedded1_embedded2
Select table: class_top_embedded1
Select table: class_top_embedded1_embedded2
Select table: class_top_embedded1_embedded2_embedded5
Select table: class_top_embedded1_embedded2
Select table: class_top_embedded1_embedded2_embedded5
Select table: class_top_embedded1_embedded2_embedded6
Select table: class_top_embedded1_embedded2
Select table: class_top_embedded1_embedded2_embedded6
Select table: class_top_embedded1_embedded3
Select table: class_top_embedded1
Select table: class_top_embedded1_embedded3_embedded4
Select table: class_top_embedded1_embedded3
Select table: class_top_embedded1_embedded3_embedded4
Select table: class_top_embedded1_embedded3
Select table: class_top_embedded1_embedded3_embedded6
Select table: class_top_embedded1_embedded3
Select table: class_top_embedded1_embedded3_embedded6
Select table: class_top_embedded1
Select table: class_top_embedded1_embedded4
Select table: class_top_embedded1
Select table: class_top_embedded1_embedded4
Select table: class_top_embedded1
Select table: class_top_embedded1_embedded5
Select table: class_top_embedded1
Select table: class_top_embedded1_embedded5
Select table: class_top
Create object: ObjKey(2)
...

And with these changes we have the equivalent log:

Select table: class_top
Create object: ObjKey(1)
Create object: ObjKey(2)

...

In this particular test, I observe the following size difference:
Before changes:
Logical file size: 294M
History size: 34.5M
After changes:
Logical file size: 262M
History size: 1.5M

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed
  • bindgen/spec.yml, if public C++ API changed

@ironage ironage self-assigned this Jul 19, 2024
@cla-bot cla-bot bot added the cla: yes label Jul 19, 2024
@ironage
Copy link
Contributor Author

ironage commented Jul 19, 2024

Edit: Fixed. This is in draft because I think collections are missing insertions for some reason. Details below:

Before:

Select table: flx_pending_bootstrap
Create object: ObjKey(1)
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select table: flx_pending_bootstrap_changesets
--------------------------------------------
Select table: flx_subscription_sets
Modify object: state on ObjKey(1)
Modify object: error on ObjKey(1)
--------------------------------------------
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 1
Select table: flx_pending_bootstrap_changesets
--------------------------------------------
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 2
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 3
Select table: flx_pending_bootstrap_changesets
--------------------------------------------
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 4
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 5
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 6
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 7
Select table: flx_pending_bootstrap_changesets
--------------------------------------------
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 8
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 9
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 10
Select table: flx_pending_bootstrap_changesets
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 11
Select table: flx_pending_bootstrap_changesets
--------------------------------------------

After:

Select table: flx_pending_bootstrap
Create object: ObjKey(1)
--------------------------------------------
Select table: flx_subscription_sets
Modify object: state on ObjKey(1)
Modify object: error on ObjKey(1)
--------------------------------------------
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 1
--------------------------------------------
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 2
--------------------------------------------
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 6
--------------------------------------------
Select table: flx_pending_bootstrap
Select collection: changesets on ObjKey(1)
Collection insert at 10

@ironage ironage force-pushed the js/bootstrap-perf branch 2 times, most recently from 59f3be7 to 57f9643 Compare August 1, 2024 19:27
fix collection notifications after embedded object creations

cleanup state, and avoid excessive collection selections

fix trace logging
@ironage ironage changed the title reduce unnecessary table selections in replication RCORE-2223 reduce unnecessary table selections in replication Aug 1, 2024
@ironage ironage marked this pull request as ready for review August 1, 2024 22:01
@ironage ironage linked an issue Aug 1, 2024 that may be closed by this pull request
Copy link

coveralls-official bot commented Aug 1, 2024

Pull Request Test Coverage Report for Build james.stone_582

Details

  • 304 of 359 (84.68%) changed or added relevant lines in 3 files are covered.
  • 68 unchanged lines in 13 files lost coverage.
  • Overall coverage decreased (-0.006%) to 91.094%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/replication.cpp 34 44 77.27%
test/test_replication.cpp 263 308 85.39%
Files with Coverage Reduction New Missed Lines %
src/realm/mixed.cpp 1 86.46%
src/realm/sort_descriptor.cpp 1 94.06%
test/fuzz_tester.hpp 1 57.73%
src/realm/replication.cpp 2 80.55%
src/realm/replication.hpp 2 81.0%
src/realm/sync/noinst/client_impl_base.cpp 2 83.24%
src/realm/sync/client.cpp 3 90.96%
src/realm/sync/network/network.cpp 3 87.95%
src/realm/sync/noinst/protocol_codec.hpp 4 73.82%
src/realm/util/assert.hpp 4 87.1%
Totals Coverage Status
Change from base Build 2537: -0.006%
Covered Lines: 217067
Relevant Lines: 238289

💛 - Coveralls

CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines 477 to 480
ConstTableRef table = coll.get_table();
ColKey col_key = coll.get_col_key();
ObjKey obj_key = coll.get_owner_key();
auto path = coll.get_stable_path();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the values here and passing them to do_select_collection() rather than passing the collection in is a bunch of extra instructions for no benefit and the structure of this means that the compiler can't inline it away.

The idea behind this division is that select_collection() gets inlined into each of the callers so that no function call is needed in the common case of the collection already being selected, but the less common case is outlined rather than being repeated for each called. This is a fairly dubious optimization that we haven't actually measured in the last decade, but it theoretically could be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation. I cleaned it up a bit, hopefully this makes it easier for the compiler to make optimizations.

{
if (key != m_selected_obj) {
do_select_obj(key);
bool newly_created = check_for_newly_created_object(key, table);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't appear to be any obvious reason we have to check this every time rather than caching it and only checking when selecting an object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a valid optimization, changed.

@ironage ironage merged commit a3ff80b into master Aug 6, 2024
46 checks passed
@ironage ironage deleted the js/bootstrap-perf branch August 6, 2024 16:05
@github-actions github-actions bot mentioned this pull request Aug 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Further optimize transaction logs of bootstrap downloads
3 participants