Repository navigation
Store: replace ReadWriteNode/UnfrozenInternalNode with plain nodes, hidden state and a dirty-read lock - #6063
Open
William Wong (compulim) with Copilot wants to merge 13 commits into
Open
William Wong (compulim) with Copilot wants to merge 13 commits into
William Wong (compulim) with Copilot wants to merge 13 commits into
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…-field state, dirty-read lock, toJSON rejection Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
William Wong (compulim)
marked this pull request as ready for review
November 20, 2026 23:19
William Wong (compulim)
requested review from
Eugene (OEvgeny),
William Wong (compulim),
Chris Whitten (cwhitten) and
Thomas Durnford (tdurnford)
as code owners
November 20, 2026 23:19
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
This branch has not been deployed
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.
The node model from #6053 had three kinds of node:
FrozenInternalNode,UnfrozenInternalNodeand theReadWriteNodeclass. Repeated upserts on a large parent also cost O(children) per call. This PR keeps nodes plain at every boundary userland sees. Store-only data goes into hidden private fields, andhasPart/isPartOfare updated by delta instead of being recomputed.Node model
FrozenInternalNode).createNode()returnsDraftNode(renamed fromUnfrozenInternalNode): validated, with deep-frozen values, but the object itself is not frozen.private/draft.tsreplaces theReadWriteNodeclass with a plainDraftrecord plus functions:createDraft,readDraft,commitDraft,setDraftPartOf,removeDraftReferencesTo,getDraftReferenceIds.commitDraftfreezes an owned node in place when possible. Otherwise it rebuilds the node in one O(properties) pass (nodelete), keeps key order, and reuses aFrozenNodeSetwhose IDs haven't changed.private/hiddenNodeState.tsstores the cacheddateCreatedtime and sorted children as private fields, using the constructor-return trick.Object.keys, spread andJSON.stringify.JSON.parse(JSON.stringify(node))clone),getDateCreatedTime()re-parsesdateCreated.npm run benchmark:node).ReadWriteNode,freezeNode,dateCreatedTime.tsand the symbol-based sorted-children getter.upsert()semanticsfinally, so it can only be changed inside its own updater.upsert()/delete()inside an updater. Nested calls throw before any state changes.getSnapshot()etc.) is still allowed.hasPart/isPartOfit received, the store skips validating and diffing them. The nesting ban is what makes this safe: the sets shown to the updater are still current when it returns.createNodetoJSON(), own or inherited.toJSON()is still called inside a JSON literal's@value.hasPart/isPartOfthat are already aFrozenNodeSetskip valibot validation and are reused as-is (about 300 µs saved per 1,000 parts).Benchmarks
New store-level rows in
benchmark.ts, plus a newbenchmark.node.ts(npm run benchmark:node):Other rows (Append, Random, Delete, Iterate, identifier rows, memory per node) are unchanged or slightly better. "Update parent add one" is still O(N), because the updater copies
hasPartitself withnew Set(...).Trade-offs for review
Draft; they are recomputed on every change at O(properties).OPINIONS.mdnow documents thetoJSONrule, the dirty-read lock and the hidden-state rebuild.