Skip to content

fix(standalone): compile retained WebAssembly assets for AOT - #182304

Merged
steipete merged 2 commits into
mainfrom
fix/standalone-static-wasm
Oct 24, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/standalone-static-wasm

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes slow image, PDF, voice, command parsing, Code Mode, Matrix crypto, and archive operations in experimental AOT standalone builds.

User Impact

Retained WebAssembly workloads can use compiled native code in AOT artifacts. Standard JIT and bytecode builds keep their existing packaging. AOT executables grow to hold the compiled code; the sidecar still supplies the bytes consumed by each library's existing lazy loader.

Why This Change Was Made

The existing sidecar resource plan already owns which assets survive plugin selection. The final compiler now receives literal .wasm imports from that plan, deduplicated by byte identity. QuickJS's encoding.so is registered as WASM, and Opus's current inline payload is decoded at build time under an explicit decoder contract. Libraries keep their existing initialization and resource loading. The manifest records source paths, SHA-256, and sizes for the included modules. Content-addressed registration imports also carry every WASM byte change into the shared module-graph fingerprint used by matched AOT/JIT support artifacts. All new state stays in builder scratch; there is no runtime registry.

Evidence

node scripts/bench-standalone-wasm.mjs "$AOT_BUN" ./wasm-probe compiles small dependency probes only. All eight workloads matched across JIT, JIT with registration, dynamic-WASM AOT, and static-WASM AOT. Checks cover full PCM/image/PDF text and RGBA/tree-expression/TAR-manifest hashes, plaintext crypto roundtrips, and numeric guest results. QuickJS and encoding modules transfer to a real worker that closes naturally. Hashing runs outside the measured interval. Every WASM asset was byte-verified against the current frozen workspace install.

Five fresh-process samples per mode, interleaved; batch timing follows two workload warmups. macOS arm64, Bun AOT toolchain 1.4.4-canary.1+5d8fe974f, identical dependency bytes throughout. Times are milliseconds. This was a busy shared host (load averages 45.75/46.14/51.26), so these library batches are the scope of the performance result.

Workload JIT CPU control AOT CPU median AOT wall median AOT wall p95
Opus encode/decode, 100 frames 109.04 437.12 → 13.35 538.89 → 16.49 907.98 → 27.80
Photon resize/PNG, 10 images 21.17 364.51 → 7.76 507.36 → 7.93 742.02 → 18.91
PDFium text/render, 5 pages 30.81 43.97 → 1.65 53.43 → 2.10 58.16 → 2.91
tree-sitter Bash, 10 parses 63.35 321.78 → 8.68 377.65 → 10.72 409.20 → 15.20
QuickJS + encoding, 10 guest runs 24.18 144.42 → 4.38 150.87 → 4.43 170.93 → 5.02
Matrix backup crypto, 30 roundtrips 39.03 433.77 → 13.41 495.59 → 17.88 517.88 → 22.17
fs-safe TAR, 10 × 100 entries 38.16 37.80 → 5.06 53.37 → 5.81 76.70 → 7.93
QuickJS modules transferred to worker 35.51 156.51 → 5.03 188.08 → 6.30 291.64 → 6.35

Compiled WASM increases executable size; these separate probe binaries include that machine code and retain library input bytes. Full standalone release qualification is outside this focused evidence; no whole-application AOT build was run.

Focused checks passed: pnpm test test/scripts/bun-standalone-wasm.test.ts test/scripts/bun-standalone-support.test.ts test/scripts/bun-standalone-contract.test.ts --maxWorkers=1 (32 tests; 4.10 s wall), targeted script/test lint, scoped formatting, the three tests' type project, and the tooling test typecheck leaf. The new fingerprint regression failed with the original fixed registration path and passed with content-addressed imports. The combined pre-fix replay also exposed a missing dependency in the support test fixture (2 failed, 6 passed; 7.41 s wall), corrected on main separately. Independent Codex review is scoped-clean through P2 with no remaining findings.

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 24, 2026 06:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T08:32:59.020723Z 7c726ae New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: L labels Oct 24, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds compile-time imports for retained WebAssembly assets in experimental AOT standalone builds while preserving existing library loaders.

Example: Encode and decode 100 Opus frames in the supplied macOS arm64 dependency benchmark.

  • Before: The reported dynamic-WASM AOT median was 423.84 ms of CPU time.
  • After: The reported registered-WASM AOT median was 12.85 ms, with matching output.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation is focused and source-consistent, with useful dependency benchmarks but limited integration confidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its macOS arm64 dependency probes exercise registration and real worker transfer, while full standalone integration remains unverified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: WASM-heavy operations run slowly in experimental AOT standalone artifacts because their modules are loaded dynamically.
Reason: The maintainer-authored direction has measured workload value, preserves existing loaders, and explicitly accepts executable growth.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides a useful, maintainer-directed AOT performance improvement that current main lacks, with no concrete introduced defect found.

Priority: P2
Reviewed head: 3839eff8758748f34b0f486421fe77bf6a5ae333

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise a builder-produced AOT artifact and its embedded worker workload, and does not show a regression failing on the base.
Agent review details

How this fits together

The standalone builder consumes a completed runtime build and its sidecar resource plan, then produces an executable, companion runtime directory, and packaging manifest.

flowchart TD
  A[Completed runtime build] --> B[Plugin selection and resource plan]
  B --> C[AOT WASM import generation]
  C --> D[Bun executable compilation]
  B --> E[Retained sidecar bytes]
  D --> F[Library and worker workloads]
  E --> F
Loading

Technical review

Best possible solution:

Use the existing sidecar plan to supply byte-identical WASM compiler inputs without introducing a competing runtime loader.

Do we have a high-confidence way to reproduce the issue?

Current main lacks static registration, and the benchmark compiler's documented contract explains why dynamically loaded modules use the interpreter; the author supplies comparative dependency results, but this review ran no target code.

Is this the best way to solve the issue?

The change addresses the compiler boundary directly, retains sidecar ownership and lazy loading, and avoids runtime patches or duplicate asset-selection state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6ba8529d86d3.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced diff limits registration to AOT mode, consumes the existing resource plan, and imports registration through the native bootstrap. (scripts/build-bun-standalone.mjs:569, 3839eff87587)
  • Current-main behavior: Fetched main proceeds from sidecar planning to bootstrap replacement without preparing static WASM imports. (scripts/build-bun-standalone.mjs:562, 6ba8529d86d3)
  • Bounded build-time implementation: The generator validates module bytes, deduplicates compiler inputs by SHA-256, and decodes the pinned Opus format without evaluating dependency code. (scripts/lib/bun-standalone-wasm.mjs:89, 3839eff87587)
  • Authoritative compiler contract: This dependency contract applies because the patch feeds literal WASM imports to Bun's AOT compiler; the benchmark revision documents recognition by exact module bytes regardless of the runtime loading API. (docs/bundler/aot-compatibility.mdx, 5d8fe974fc89)
  • Supplied performance evidence and accepted tradeoff: The full PR body reports matching results across eight dependency workloads and explicitly accepts larger AOT executables; it also states that no whole-application AOT build was run. (3839eff87587)
  • Compatible artifact metadata: The additional embedded.webAssembly inventory leaves existing manifest identity fields intact; the runtime manifest reader selects known fields and ignores embedded metadata. (cli-invocation.mjs:40, 3839eff87587)

Likely related people:

  • Peter Steinberger: Raw commit 9df2906 adds scripts/build-bun-standalone.mjs:550 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9df29068d92a; files: scripts/build-bun-standalone.mjs)

PR surface

Tests +158, Docs +26, Other +463. Total +647 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 158 0 +158
Docs 1 26 0 +26
Config 0 0 0 0
Generated 0 0 0 0
Other 3 467 4 +463
Total 5 651 4 +647

Labels

Label changes:

  • add P2: The improvement addresses substantial computational overhead in explicitly experimental AOT artifacts while preserving production JIT and bytecode packaging.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The improvement addresses substantial computational overhead in explicitly experimental AOT artifacts while preserving production JIT and bytecode packaging.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Exercise a builder-produced AOT artifact through a retained WASM workload and an embedded worker.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 24, 2026, 2:43 AM ET / 06:43 UTC.

@steipete
steipete merged commit 38ac212 into main Oct 24, 2026
107 of 109 checks passed
@steipete
steipete deleted the fix/standalone-static-wasm branch October 24, 2026 08:41
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant