perf(zql): reduce allocations with frozen sentinel and object reuse#5609
Draft
Karavil wants to merge 1 commit intorocicorp:mainfrom
Draft
perf(zql): reduce allocations with frozen sentinel and object reuse#5609Karavil wants to merge 1 commit intorocicorp:mainfrom
Karavil wants to merge 1 commit intorocicorp:mainfrom
Conversation
|
Someone is attempting to deploy a commit to the Rocicorp Team on Vercel. A member of the Team first needs to authorize it. |
3fc6d52 to
a9dba77
Compare
This was referenced Feb 25, 2026
d544f50 to
80802a0
Compare
|
Deployment failed with the following error: |
d544f50 to
80802a0
Compare
…euse
Two allocation reduction optimizations for the IVM push hot path:
1. Shared EMPTY_RELATIONSHIPS sentinel: Replace per-node {} allocation
with a frozen shared object, reducing GC pressure during fetch and push.
2. Reuse outputChange objects in genPush: Pre-allocate reusable objects
and mutate row fields before yielding, instead of creating new objects
per connection.
Object reuse is safe because filterPush consumers are synchronous within
the generator chain.
80802a0 to
b55846f
Compare
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.
Summary
Reduce GC pressure on the IVM push hot path with two allocation optimizations.
Motivation
During IVM push operations, every source change is propagated to all connected pipelines. For each connection, the current code creates fresh
NodeandChangeobjects with newrelationships: {}literals. In a workload with 135 IVM pipelines processing ~200 row changes, this creates thousands of short-lived objects per push cycle, increasing GC pressure and pause time.Similarly,
generateWithOverlayInnercreates{row, relationships: {}}node objects for every row during fetch, adding more allocation overhead on the fetch hot path.Changes
EMPTY_RELATIONSHIPSfrozen sentinel at module scope, replacing per-node{}allocation ingenerateWithOverlayInner(3 sites) andgenPush(via reuse objects)Changeobjects ingenPush(reuseNode,reuseOldNode,reuseAddRemove,reuseEdit) and mutaterowfields before yielding, instead of creating new objects per connection per pushSafety
Object reuse in
genPushis safe becausefilterPushconsumers are synchronous within the generator chain. Eachyield* filterPush(...)completes fully before the next loop iteration mutates the reused objects. There is no concurrent access.Expected Performance Impact
For 135 IVM pipelines each processing ~200 rows, this eliminates thousands of short-lived
{}andChangeobject allocations per push cycle. The frozen sentinel also enables V8 to share the same hidden class across all nodes, improving inline cache hit rates for downstream consumers that readnode.relationships.Testing
Stack Order
This PR is part of a stacked series of IVM performance optimizations. Merge in order:
Independent PRs (no conflicts): #5607 (BTree iterators), #5608 (Join optimizations)