Skip to content

perf(bun): compress embedded assets with byte-exact registration - #10053

Closed
proggeramlug wants to merge 4 commits into
mainfrom
fix/bun-embedded-asset-compression-20260911
Closed

proggeramlug wants to merge 4 commits into
mainfrom
fix/bun-embedded-asset-compression-20260911

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Scope

Independent Bun-platform embedded-asset compression. Based on main 603b074ac;
does not depend on the child-output, own-bind, or generator PRs, and no extracted
application, credentials, account, or Bun installation is needed for its tests.

  • Use checksummed level-3 zstd only for payloads at least 4 KiB with over 64 bytes saved;
    require at least 256 KiB of aggregate payload savings. Otherwise retain raw
    embedding. Existing non-Bun behavior is unchanged.
  • Reuse the existing bun-cli-utils dependency/feature selection. No dependency,
    default feature, environment knob, or existing exported ABI is changed.
  • New registration API validates exact frame and decoded lengths, excludes
    trailing/concatenated data, preserves explicit file/text loader metadata,
    and publishes only decoded bytes. Constructor failure is fatal.
  • Decoded bytes use immortal native storage; no JavaScript or GC startup
    is required. This trades compressed image bytes for native heap storage at
    startup, and is not a peak-memory reduction claim.
  • Compressed symbols are separate from the old raw-data symbol namespace.

Validation

At exact head d8c817ef1f69bf7121bd9fb880eb7908ecb57743, the full normal-debug
runtime suite passed 3,529 tests, no failures, four ignored, on one thread.
This includes all five new compression tests: empty/Unicode/NUL/binary bytes,
malformed/truncated/trailing/concatenated frames, checksummed payload damage,
metadata mismatch, retained ownership and no publication on failure. All three
compiler packaging tests passed, including incompressible/raw controls.
All 13 compiler embedding tests pass (including those three new tests).
Formatting, whitespace, file caps and JavaScript syntax checks pass.

The full script tier reports 75 passes, one failure, two CI-only skips;
compile-tier lint is explicitly skipped locally. The sole failure is public
benchmark artifact freshness, also present in the exact base-main
603b074ac push run 34565492075.
Current-head Linux runtime CI also passes all five new tests: 3,509 passed,
one failed, four ignored. Its sole failure is the identical main stack-size
assertion at native_stack.rs:53/:60 (bound must belong to this worker).
Current zizmor reports only the unchanged gate-failure-watch.yml trigger;
the triggering workflow, zizmor workflow and configuration are unchanged.

The frozen before-fix compiler 81b47b47c compiles the new native fixture,
then fails its compression-liveness assertion (zero registrations,
three required), rather than failing setup. Native execution is not reached
in that negative control.

The final clean-commit compiler and all nine matching provider archives have
been built and frozen at d8c817ef1. Compiler/default graph: 3m31s;
provider/Wasm graph: 5m14s. An earlier combined invocation incorrectly enabled
Wasm host externs inside the compiler and was rejected at linking; the restored
two-stage build passes without source changes or archive/stamp substitutions.

The standalone native matrix passes under both default and compact GC, with
Wasm enabled. It proves three assets actually take the compressed path, moves
the source directory away, and checks exact filesystem bytes, Bun.file,
explicit text-loader require, raw/empty controls and retained values after GC
against pinned Node. Neither test needs extracted application files.

Additional local real-emitter measurement packages 1,825 recorded asset payloads
in a small independent program: the asset object decreases from 42,629,960
to 17,379,160 bytes
, a 25,250,800-byte reduction. All 1,825 actual emitted
payload hashes match the originals (934 compressed, 891 raw); both native
programs read every embedded file with the source directory hidden. This
compares same-compiler Node/raw vs Bun/compressed asset objects; whole-program
platform linkage differs, so its executable difference is not attributed solely
to compression. No full application rebuild or application-size claim is made.

Linux check and warnings pass at d8c817ef1. Its scoped native job exposed an
own CI setup error: it inherited Node 22.23.2, failing the required
26.5.1 assertion before any native compilation. This was not attributed to
main or hidden by relaxing the oracle. Follow-up head
7793a66e3e999e3404f01377978b29bdff35288c installs Node from .node-version
and verifies the version before costly native builds. The actual workflow
preflight passes with the correct pin and fails with a deliberately wrong pin;
its setup/verification/build order and conditional guards are checked.

That follow-up changes only CI and the changeset; git diff d8c817ef1 -- crates scripts is empty. The frozen native results above remain at d8c817ef1, not a
claim of a fresh compiler build at the CI-only head. Final script lint again
reports 75 passes, the same inherited benchmark freshness failure, two
CI-only skips
, with compile tier explicitly skipped. At exact head 7793a66e,
Linux scoped native CI
now passes: standalone_compressed_asset_regression actually executed and
passed in 127.61 seconds, after the pinned-Node verification. Check/warnings
also pass. The runtime job remains red only on the same main stack-size
assertion (3,509 passed, one failed, four ignored).

All jobs in that run have now finished. Shards 4 and 6 pass; all ten printed
failure/crash diagnostics
in shards 1/2/3/5 exactly match main 603b074ac
run 34565492075, including the WebCrypto 10-second timeout. The comparison
covers reported exit codes and printed output excerpts, not full stdout.
GC stress has byte-exact Node parity in 588/588 cells: 429 PASS, 159
UNVERIFIED, 0 FAIL
. The inert 159 arms are not moving-GC evidence. The
fan-in is red on the documented baseline failures; this is not an all-green
CI claim or a claim that compression was exercised by the gap/GC suites.
Its live compression proof is the scoped native test explicitly named above.

No claim that the full application works or reaches 300 MB. Ready for
maintainer review; the merge train can perform the patch-version bump.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: a81fc087-25a3-42d7-8c24-044e744ef3e6

📥 Commits

Reviewing files that changed from the base of the PR and between d8c817e and 7793a66.

📒 Files selected for processing (2)
  • .github/workflows/test.yml
  • changelog.d/10053-bun-embedded-asset-compression.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • changelog.d/10053-bun-embedded-asset-compression.md

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

Bun embedded assets now use checksummed zstd compression when size thresholds are met. Generated code registers compressed payloads through a new runtime API, which validates and decodes them into persistent storage. Tests cover compiler output, runtime validation, loaders, and retained asset data.

Changes

Bun embedded asset compression

Layer / File(s) Summary
Compression preparation
crates/perry/src/commands/compile/embed/compression.rs
Adds threshold-based checksummed zstd compression. Small, incompressible, or low-savings assets remain raw.
Runtime decoding and registration
crates/perry-runtime/src/embedded.rs, crates/perry-runtime/src/embedded/compressed.rs
Adds the feature-gated registration API. The runtime validates frames, decodes exact lengths, preserves text-module metadata, and retains decoded bytes for the process lifetime.
Compiler emission and wiring
crates/perry/src/commands/compile/embed.rs, crates/perry/src/commands/compile/run_pipeline.rs
Passes the Bun platform flag, emits compressed payload symbols and zstd declarations, and generates compressed or raw registration calls.
End-to-end validation and release support
scripts/test-bun-embedded-compression.mjs, crates/perry/tests/bun_embedded_compression.rs, changelog.d/10053-bun-embedded-asset-compression.md, .github/workflows/test.yml
Adds regression coverage for asset integrity, loaders, garbage-collection retention, and raw fallback. Updates the changelog and scoped test build selection.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Compiler
  participant GeneratedBunBinary
  participant PerryRuntime
  participant EmbeddedAssetRegistry
  Compiler->>Compiler: compress eligible embedded assets
  Compiler->>GeneratedBunBinary: emit zstd payload and registration call
  GeneratedBunBinary->>PerryRuntime: register compressed asset
  PerryRuntime->>PerryRuntime: validate and decode zstd frame
  PerryRuntime->>EmbeddedAssetRegistry: publish decoded bytes and metadata
Loading

Suggested reviewers: jdalton

Merge Risk: ⚪ Minimal · up to 7793a

The scoped native-test setup validates the repository-pinned Node version and correctly includes the embedded-compression suite's required runtime preparation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 7 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: checksummed compression of Bun embedded assets with byte-exact registration.
Description check ✅ Passed The description is detailed and directly covers scope, implementation behavior, validation results, known baseline failures, and CI follow-up. It does not use the template headings and does not explic…
Full details: Docstring Coverage

Explanation

Docstring coverage is 72.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 7 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bun-embedded-asset-compression-20260911

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug marked this pull request as ready for review September 11, 2026 09:32
@proggeramlug

Copy link
Copy Markdown
Contributor Author

Landed with preserved authorship via #10082 (rebase merge 435d639); the merged tree was verified byte-identical to the audited Train160 tree. Closing this superseded original PR.

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