perf: avoid per-read emptiness scan getCollectionData#812
Open
TMisiukiewicz wants to merge 2 commits into
Open
perf: avoid per-read emptiness scan getCollectionData#812TMisiukiewicz wants to merge 2 commits into
TMisiukiewicz wants to merge 2 commits into
Conversation
40 tasks
TMisiukiewicz
marked this pull request as ready for review
July 23, 2026 07:55
TMisiukiewicz
force-pushed
the
perf/getcollectiondata-empty-object
branch
from
July 23, 2026 07:59
6274571 to
8bdc36a
Compare
Contributor
|
I will review this by the end of the day |
fabioh8010
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
Problem
OnyxCache.getCollectionData()callsisEmptyObject(snapshot)on every read to decide whether to return the collection or the empty-collection fallback. Profiling the Search page (4× CPU throttle) showed this check is a significant cost:isEmptyObjectaccounted for ~919 ms of self-time, called almost entirely fromgetCollectionData.getCollectionDataper collection key confirmed the emptiness check dominates read time and that its cost scales with collection size:report_transactions_reportActions_transactionViolations_(small)Rebuilds were negligible (≤4 across the run), so the cost is the per-read check itself, not snapshot rebuilding.
Solution
Store the shared frozen-empty object (
FROZEN_EMPTY_COLLECTION) as the snapshot for empty collections instead of a fresh{}. The read path then:undefinedfor a collection that was never stored,snapshot === FROZEN_EMPTY_COLLECTIONreference comparison (no key scan),isEmptyObjectno longer runs on populated data at all.Emptiness is now determined once, at snapshot-build time (
rebuildCollectionSnapshot, which is dirty-gated and rare), rather than on every read.Performance improvement:
On large account and staging, I was able to record 500-1000ms spent on
isEmptyObjectingetCollectionData. On dev, it was 400-700ms before and 11ms after.Related Issues
$ Expensify/App#96855
Linked E/App PR
Expensify/App#96853
Automated Tests
Unit tests already cover it, added only one missing
Manual Tests
Author Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool &&.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari