Skip to content

Decompose StateImpl class for tree-shaking#35

Merged
nerdalytics merged 8 commits into
trunkfrom
feat/tree-shaking
Feb 8, 2026
Merged

Decompose StateImpl class for tree-shaking#35
nerdalytics merged 8 commits into
trunkfrom
feat/tree-shaking

Conversation

@nerdalytics
Copy link
Copy Markdown
Owner

@nerdalytics nerdalytics commented Feb 8, 2026

Summary

  • Replace monolithic StateImpl class with module-level functions and a createState closure factory, enabling bundlers to tree-shake unused exports
  • Add benchmark suite for validating performance across all primitives
  • Add per-benchmark heap usage reporting (heap=XXkb) using process.memoryUsage().heapUsed with forced GC
  • Add sideEffects: false to package.json
  • Backport v2 SVG logo from epoch-2, update both READMEs
  • Bump devDependencies: biome 2.3.14, @types/node 25.2.2, npm 11.9.0
  • Update architecture docs to reflect the new closure-based design

Results

Tree-shaking: Importing only state reduces bundle from 5,443 bytes to 680 bytes (87.5% reduction). createDerive, createSelect, createLens, createEffect are all eliminated when unused.

Performance (A/B, same session):

  • Pure get(): -39% (closure eliminates instance.get() indirection)
  • Pure set(): -32%
  • Signal reading: -39%
  • Signal creation: -8.5%
  • No regressions outside noise

Test plan

  • All 114 tests pass, no test changes needed
  • Biome lint: 0 errors
  • Build (tsc + uglify): success
  • Benchmark A/B comparison via git worktree
  • Tree-shake validation with esbuild (state-only consumer)
  • Benchmark runs with --expose-gc, heap column reports meaningful values

Replace monolithic StateImpl class with module-level functions and
a createState closure factory. Bundlers can now eliminate unused
exports — importing only `state` drops derive, select, lens and
all lens helpers (87.5% size reduction for state-only consumers).
Measure heap delta per benchmark run using process.memoryUsage().heapUsed
with forced GC before each run for a clean baseline. Reports median heap
delta in KB alongside existing timing stats. Adds --expose-gc flag to the
benchmark npm script.
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Feb 8, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​types/​node@​25.0.10 ⏵ 25.2.2100 +110081 +196100
Updated@​biomejs/​biome@​2.3.13 ⏵ 2.3.14100 +110010099 +2100

View full report

@nerdalytics nerdalytics merged commit cb74ce1 into trunk Feb 8, 2026
12 checks passed
@nerdalytics nerdalytics deleted the feat/tree-shaking branch February 8, 2026 10:33
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.

1 participant