Skip to content

perf(pack): write the library snapshot in one stream per kind of value - #2373

Merged
HuiJun merged 1 commit into
developfrom
perf/pack-columnar-streams
Nov 18, 2026
Merged

HuiJun merged 1 commit into
developfrom
perf/pack-columnar-streams

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The js/wasm size budgets have been raised repeatedly (#2367, #2355, #2187) and three pull requests were blocked on the engine budget by a few KB of their own code (#2354, #2294, #2335). This returns about 0.7 MB gzipped to every artefact that embeds the library snapshot, without removing anything.

The embedded snapshot is 4.16 MB raw and was 1.63 MB of each gzipped artefact. internal/syntax/pack wrote every value into one byte stream — a length, a string index, a span delta, a boolean — and that interleaving defeats gzip, although each kind on its own is very regular. The writer now keeps one stream per kind of value (lengths, booleans, floats, unsigned, signed, string indices), and splits each multi-byte varint into its first byte and its tail. A section is led by the lengths of its streams, so it is still decoded apart from the rest. The snapshot is the same size raw (4,157,811 → 4,157,921 bytes) and gzips to 0.95 MB.

The encoding is lossless and knows nothing about the content. Because the bytes differ, snapshotFormatVersion (31 → 32) and the on-disk record formatVersion (36 → 37) are bumped, so an older cache entry is rejected and rebuilt rather than misread; the pinned symbol-kind digest moves only because it includes the format number.

Gzipped sizes from make wasm-check (go1.27.4), develop 36c76c4 against this branch. No budget constant is changed.

artefact before after change budget
sysml-engine 11,196,498 10,479,848 −716,650 11,300,000
browser REPL sysml 16,418,151 15,708,823 −709,328 16,500,000
sysml-core 7,508,010 6,818,407 −689,603 7,600,000
sysml-syntax (no snapshot) 1,665,233 1,665,243 +10 1,800,000
combined sysml-wasm 11,811,864 11,094,836 −717,028 12,000,000

How it was verified

  • go build ./..., go vet ./..., gofmt -l . (empty), go test -count=1 ./..., make lint, go test -C tools ./referee/apijson and make wasm-check pass on this head, with the snapshot regenerated by make stdlib-snapshot.
  • The existing snapshot contract tests are unchanged and pass: the decoded index equals a fresh load of the library, and re-encoding is byte-stable.
  • internal/syntax/pack tests: the malformed-input cases are rewritten for the new layout and extended (missing or overlong stream lengths, unterminated and overflowing varint tails, lengths beyond the bytes left, a section longer than its stream, reads past a stream); a new test checks that each kind lands in its own stream and that values read back in any interleaving. Trailing bytes after the last stream are still reported by Done.
  • Decode time is unchanged: BenchmarkDecodeSnapshot 11.6 → 11.1 ms (mean of 8), 42.2 MB and 72.1 k allocations in both.

Not run locally: the -race suite (make test); the plain go test ./... suite was run instead.

Checklist

  • make test and make lint pass locally — make lint and go test ./... yes; -race left to CI
  • Tests added or updated for the change
  • Documentation extended where it already covers the surface (docs/internals/architecture.md, docs/internals/performance.md)
  • Changelog entry added as changes/unreleased/pack-columnar-streams.performance.md
  • baselines regenerated and make docs-counts run if a gate count moved — none moved
  • No internal work-item labels in the body, docs, or changelog

🟢 Devin Review found nothing to fix · View findings

Devin Review

Co-Authored-By: jason.han <hanhuijun@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review November 18, 2026 02:46

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@HuiJun
HuiJun added this pull request to the merge queue Nov 18, 2026
Merged via the queue into develop with commit 0860432 Nov 18, 2026
114 of 152 checks passed
@HuiJun
HuiJun deleted the perf/pack-columnar-streams branch November 18, 2026 10:54
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