Skip to content

perf: faster pack/unpack (no breaking changes) - #35

Open
adarshmadrecha wants to merge 1 commit into
rgcl:mainfrom
adarshmadrecha:perf-improvements
Open

perf: faster pack/unpack (no breaking changes)#35
adarshmadrecha wants to merge 1 commit into
rgcl:mainfrom
adarshmadrecha:perf-improvements

Conversation

@adarshmadrecha

Copy link
Copy Markdown

Summary

Internal performance improvements to pack / unpack with no API or packed-format changes.

Changes

  • Tagged integer AST leaves instead of { type, index } objects (less GC on pack)
  • Pre-sized container arrays (Object.keys / known lengths)
  • Static encode/decode maps + fast paths when escaping is unnecessary
  • Base-36 cache for common dictionary indices
  • Structure emission via parts array + join (avoids quadratic concat)
  • Object.create(null) dictionaries

Benchmark (same machine, before vs after)

Node v25 / win32 x64 / i5-1340P — full table in benchmark/COMPARISON.md.

Metric (avg across datasets)Change
Pack ops/s+73.6%
Unpack ops/s+6.9%
Pack MB/s+73.5%
Unpack MB/s+7.2%

Examples:

  • geojson-large pack: 177 → 294 ops/s (+66%), unpack: 457 → 478 ops/s (+5%)
  • api-large pack: 153 → 270 ops/s (+77%)
  • ecommerce-large pack: 102 → 220 ops/s (+116%)

CPU stays ~100% of one core during the hot loop (CPU-bound); wall-clock CPU time per op drops with throughput. RSS stays in a similar band.

Related: benchmark harness in #34.

Test plan

  • npm test — 22/22 passing (byte-identical packed fixtures)
  • Before/after bench on synthetic GeoJSON / e-commerce / API / nested datasets
  • No public API or options changes

Reduce pack allocations with tagged-integer AST leaves, pre-sized
containers, cached base36, static escape maps, and join-based structure
emission. Add decode fast-path. Public API and packed output unchanged.
Sign up for freeto 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

@adarshmadrecha