Prototype path-aware immutable nested writes - #1
Draft
hatim-s wants to merge 1 commit into
Draft
Conversation
Co-authored-by: GPT 5.5 <codex@openai.com> Co-authored-by: Zed <zed@zed.dev>
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.
Issue
Bolt nested writes currently go through Mutative. That keeps immutable snapshots, but it is expensive for hot leaf-write paths where Bolt already knows the exact path being replaced.
Cause
The nested write path pays general-purpose proxy/draft overhead even though the operation is always a single path replacement. A direct in-place mutation prototype was fast for primitive leaf subscribers, but it is not React-safe as a default because root and parent path subscribers rely on changed object references from
useSyncExternalStore.Implementation
set("", nextState)assignment.createBolt,createBoltStore,useStore,useSet,get,getState,subscribe, and typed paths.Object.is(previousValue, nextValue).getState()snapshots after later nested writes.Validation
bun test src/bolt/bolt.test.tsbun run build:libbun run buildFocused tests cover:
Benchmarks
Protocol: production build +
vite preview, default settings, 3 measured passes per route, median reported. Browser automation used headless Google Chrome againsthttp://127.0.0.1:4173./stress-test/stress-test/stress-test/stress-test-2/stress-test-2/stress-test-3/stress-test-3Known Limitations