Skip to content

Speedup changes collection by caching client component lookups - #795

Open
Shatur wants to merge 1 commit into
masterfrom
optimize-client-iteration
Open

Shatur wants to merge 1 commit into
masterfrom
optimize-client-iteration

Conversation

@Shatur

@Shatur Shatur commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Closes #793.

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.40%. Comparing base (8772d02) to head (38303a9).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #795      +/-   ##
==========================================
+ Coverage   90.36%   90.40%   +0.04%     
==========================================
  Files          73       73              
  Lines        4784     4804      +20     
==========================================
+ Hits         4323     4343      +20     
  Misses        461      461              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/server.rs
scan.dirty.clear();
removal_buffer.clear();

// HACK: Drop borrows before changing the element lifetime back to 'static.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't understand this part.
The clients_cache is empty at the end?
Why do we even need a clients_cache system param if it gets emptied at the end?
Can't we just rebuild the cache from the query at the start?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah it's to re-use the capacity.

@Shatur Shatur Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

clients_cache allows us to reuse the capacity. Without this every collect_changes will allocate a new Vec. I see people report a fairly large amount of clients (like 300 or so) and allocating a Vec for 300 items is quite expensive. It's the hottest path in the crate, so I'm trying to keep it optimal.

@cBournhonesque cBournhonesque left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be nice to have the benchmark results listed in the PR description I think

Base automatically changed from fix-delayed-mutation-with-insertion2 to master November 16, 2026 16:22
@Shatur
Shatur force-pushed the optimize-client-iteration branch from 4fdda1a to 38303a9 Compare November 16, 2026 16:22
@Shatur

Shatur commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, forgot to include the numbers:

Benchmark Clients Change (median) Verdict
changes_send 1 -22.02% ✅ Improved
mutations_send 1 -23.13% ✅ Improved
idle_send 1 -10.81% ✅ Improved
sparse_mutations_send 1 -43.22% ✅ Improved
mixed_archetypes_send 1 -21.51% ✅ Improved
mixed_structural_send 1 -27.35% ✅ Improved
mixed_visibility_send 1 -31.31% ✅ Improved
once_mutations_send 1 -11.98% ✅ Improved
changes_send 20 -26.03% ✅ Improved
mutations_send 20 -13.32% ✅ Improved
idle_send 20 +6.09% ⚠️ Regressed
sparse_mutations_send 20 -7.03% ✅ Improved
mixed_archetypes_send 20 -3.87% ✅ Improved
mixed_structural_send 20 +4.74% ⚠️ Regressed
mixed_visibility_send 20 +4.96% ⚠️ Regressed
once_mutations_send 20 -1.42% ~ Within noise

That regressions might be just noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.45: collect_changes ~18% slower than 0.40 with 300 clients × ~390 visible entities

2 participants