Skip to content

perf(web): compress the wasm with zstd -19 - #2650

Merged
houko merged 1 commit into
nsgo-dev:mainfrom
Laotree:feature/web-zstd
Nov 28, 2026
Merged

houko merged 1 commit into
nsgo-dev:mainfrom
Laotree:feature/web-zstd

Conversation

@Laotree

@Laotree Laotree commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Closes #2648.

Each gallery group and the docs' live app shipped their wasm as a gzip -9 copy, decoded in the page by DecompressionStream. They now ship a .zst stream written by Bun.zstdCompressSync at level 19 and decoded by zstddec. On this build every group lands at 75.0–76.9% of its gzip -9 size, and zstd decodes faster than gzip does in the page (59 ms vs 103 ms on a 55 MB wasm, measured separately).

group gzip -9 zstd -19 ratio
inputs 15,511,650 11,933,988 76.9%
apps 15,413,308 11,582,634 75.1%
docs live 6,747,915 5,109,058 75.7%

Changes

  • web-build.mjs: compressWasm writes <wasm>.zst; nsgo.json names it with codec, stream and streamSize in place of gzip and gzipSize.
  • build-gallery.mjs: fills the loader's placeholders and copies one zstddec.mjs to the gallery root, so a visitor fetches it once.
  • gallery-loader.html: the boot script is a module that imports the decoder; it still skips decoding when a host already did, by looking for the zstd frame magic.
  • live.ts: same decode path, typed where zstddec reports ArrayBufferLike.
  • zstddec@0.3.4 (MIT, 76 KB with its wasm embedded) in website/package.json; README describes the new copy.
  • web-build.test.js: the stream round-trips through the decoder.

Testing

$ bun install --frozen-lockfile
Checked 354 installs across 456 packages (no changes)

$ bun test
2 pass, 0 fail, 3 expect() calls

$ bun run typecheck
0 errors, 0 warnings, 0 hints

$ bun run build
exit 0, 369s
  • Decoded every built stream with zstddec: each is exactly nsgo.json's wasmSize bytes and its sha256 equals the hash in the file's name; no .gzip remains.
  • Loaded /gallery/inputs/app.html and /docs/ui/tabs/ in headless Chrome from the built site: both mount, with no console errors.

Risk

Medium. A revert restores gzip; the artifacts are generated and ignored, so no data or workflow changes.

The site's deploy workflow uses bun 1.4.4, and Bun.zstdCompressSync is declared in bun-types@1.4.4; the local run used bun 1.4.5. A full site build grows by about two to three minutes from compressing 15 wasm files.

🤖 Claude Opus 5.5

@github-actions github-actions Bot added size/M documentation Improvements or additions to documentation website labels Nov 27, 2026
@Laotree
Laotree force-pushed the feature/web-zstd branch 2 times, most recently from 7473720 to a8ce604 Compare November 27, 2026 11:25
@Laotree Laotree changed the title website: compress the wasm with zstd -19 perf(web): compress the wasm with zstd -19 Nov 27, 2026
The gallery and the docs' live app now ship their wasm as a .zst stream
at level 19, decoded in the page by zstddec. On the inputs group the
stream is 76.9% of the gzip -9 size, and the other groups land at
75.0-76.9%. The page decodes zstd faster than DecompressionStream decodes
gzip.

nsgo.json names the stream with codec, stream and streamSize in place
of gzip and gzipSize. Both loaders still skip decoding when a host has
already done it, by looking for the zstd frame magic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Laotree

Laotree commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Note for whoever lands this: #2644 changes gallery-loader.html and build-gallery.mjs too, so whichever lands second needs a rebase.

🤖 Claude Opus 5.5

@houko
houko merged commit 0efd3a3 into nsgo-dev:main Nov 28, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/M website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

website: compress the wasm with zstd -19 instead of gzip -9

2 participants