Skip to content

perf: revoke drafts without a proxy get - #1370

Open
g4lb wants to merge 1 commit into
immerjs:mainfrom
g4lb:perf-revoke-drafts-by-state
Open

g4lb wants to merge 1 commit into
immerjs:mainfrom
g4lb:perf-revoke-drafts-by-state

Conversation

@g4lb

@g4lb g4lb commented Nov 12, 2026

Copy link
Copy Markdown

scope.drafts_ now holds the draft states, not the draft proxies. Before this change, revokeDraft read draft[DRAFT_STATE], and each read ran the proxy get trap. Now revokeDraft gets the state directly. The output does not change.

Built dist/cjs production code, ns/op:

Benchmark Before After Change
produce on a small object with no writes 381 345 -9.5%
Update 2 nested values with autoFreeze: false 1,983 1,796 -9.5%
Update 1,000 objects in an array 633,221 584,852 -7.6%
Read 100 array items with no writes 125,348 117,060 -6.6%
Update 25 records of mixed shapes 33,163 32,239 -2.8%

I measured no slowdown on 29 benchmarks. These include Map and Set drafts, patches, createDraft and finishDraft, and array methods. Some small benchmarks change by 10-20% between rounds. On those benchmarks, I measured no significant change. I used 12 interleaved rounds and a Mann-Whitney test (Apple M2 Max, Node 24.15.0). I did not measure the speed on other engines.

Checks:

  • yarn test passes.
  • Old and new outputs matched on 1,000,000 random recipes in Node. The comparison includes results, structural sharing, frozen state, patches, and errors.
  • Old and new built outputs matched on 50,000 random recipes each in Bun and Deno.

@markerikson

Copy link
Copy Markdown
Collaborator

Nice! What happens if you run the existing benchmarks suite (possibly with an update to include existing Immer 11.x as a comparison point)?

This branch has not been deployed

No deployments
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.

2 participants