Skip to content

[not for merge] experiment: evaluate various strategies to improve performance#3276

Draft
dmaskasky wants to merge 19 commits intopmndrs:mainfrom
dmaskasky:dmaskasky-perf-idea
Draft

[not for merge] experiment: evaluate various strategies to improve performance#3276
dmaskasky wants to merge 19 commits intopmndrs:mainfrom
dmaskasky:dmaskasky-perf-idea

Conversation

@dmaskasky
Copy link
Copy Markdown
Collaborator

@dmaskasky dmaskasky commented Mar 26, 2026

Related Bug Reports or Discussions

#3275

Summary

Does the building block weak map negatively impact performance? This PR is an experiment to see if moving back to Symbol helps.

image

Check List

  • pnpm run fix for formatting and linting code and docs

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
jotai Ready Ready Preview, Comment Mar 30, 2026 2:23am

Request Review

@dmaskasky dmaskasky marked this pull request as draft March 26, 2026 05:45
@dmaskasky dmaskasky force-pushed the dmaskasky-perf-idea branch from b98c6e2 to f26a3ec Compare March 26, 2026 05:45
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 26, 2026

More templates

npm i https://pkg.pr.new/jotai@3276

commit: 7a19d66

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Mar 26, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 26, 2026

LiveCodes Preview in LiveCodes

Latest commit: 7a19d66
Last updated: Mar 30, 2026 2:22am (UTC)

Playground Link
React demo https://livecodes.io?x=id/5DMUJNTQU

See documentations for usage instructions.

@aio39
Copy link
Copy Markdown
Contributor

aio39 commented Mar 26, 2026

I ran some benchmarks to see how this change performs in practice. While the Symbol approach does show a nice improvement in atom creation (-25%), the overall impact on most hot paths appears to be modest (~1–4%). I hope this data is helpful for evaluating the direction.

Benchmark Results: WeakMap → Symbol (PR #3276)

Ran the same benchmark suite from #3275 against three versions: v2.10.0 (baseline), v2.19.0 (current), and this PR (built from source with the Symbol change applied on top of v2.19.0).

  • 10 iterations per version, randomized sequential order
  • 3 warmup runs + global.gc() + 1 timed measurement per scenario
  • Node.js with --expose-gc, NODE_ENV=production
  • Benchmarked with Claude Code AI assistance

Results (median of 10 runs, ms — lower is better)

Scenario v2.10.0 v2.19.0 PR #3276 PR vs v2.19.0 PR vs v2.10.0
Atom Creation (10k) 0.747 0.812 0.607 -25.3% -18.8%
Primitive R/W (10k) 10.445 71.192 68.814 -3.3% +558.8%
Derived Chain (depth=100) 1.850 1.656 1.594 -3.7% -13.8%
Wide Fan-Out (1→1000) 7.265 16.754 16.557 -1.2% +127.9%
Diamond (100 mid) 0.796 1.934 1.997 +3.3% +150.8%
Subscription Churn (1k) 1.915 6.800 6.783 -0.3% +254.1%
Computed Read (10k) 2.331 13.393 12.942 -3.4% +455.1%
selectAtom (10k) 26.808 146.997 143.109 -2.6% +433.8%

Summary

  • Atom creation sees a clear -25.3% improvement — the most impactful gain from this PR.
  • Most other scenarios show 1–4% improvement over v2.19.0, consistent with reducing WeakMap.get() overhead in the hot path.
  • Diamond (+3.3%) is within noise range.
  • However, the gap to v2.10.0 remains large (100–560%) across most scenarios, indicating that the WeakMapSymbol swap alone does not address the core regression introduced around v2.14.0. The frequent getInternalBuildingBlocks() calls and the overall buildingBlocks indirection architecture appear to be the larger bottleneck.

Ref: #3275

Overwrite every benchmarks experiment with upstream/main internals so the next commit can reintroduce each variant as a focused diff.

Made-with: Cursor
Reapply each experiment variant after the upstream-baseline commit so this latest commit cleanly shows how every experiment differs from upstream internals.

Made-with: Cursor
@dmaskasky dmaskasky force-pushed the dmaskasky-perf-idea branch from 16f68f3 to 7a19d66 Compare March 30, 2026 02:22
@dmaskasky dmaskasky changed the title experiment: evaluate various strategies to improve performance [not for merge] experiment: evaluate various strategies to improve performance Apr 1, 2026
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