Skip to content

perl: wasm-opt -O2 post-link pass to reclaim ~470 KB (kd-lfas)#833

Open
brandonpayton wants to merge 2 commits into
gascity/kd-1mr/kd-k7zy-package-perl-generated-core-module-runtime-filesfrom
gascity/kd-1mr/kd-lfas-perl.wasm-size-evaluate-wasm-opt-oz-post-link-pass-7.3m-
Open

perl: wasm-opt -O2 post-link pass to reclaim ~470 KB (kd-lfas)#833
brandonpayton wants to merge 2 commits into
gascity/kd-1mr/kd-k7zy-package-perl-generated-core-module-runtime-filesfrom
gascity/kd-1mr/kd-lfas-perl.wasm-size-evaluate-wasm-opt-oz-post-link-pass-7.3m-

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

What

Add a wasm-opt -O2 post-link, pre-fork-instrumentation pass to
packages/registry/perl/build-perl.sh; bump build.toml revision 2 → 3.

build-perl.sh links with a load-bearing --no-gc-sections (so wasm-ld's
--allow-undefined doesn't strip live Perl code) and applied no post-link size
pass, leaving dead code from the 30 curated static XS extensions. wasm-opt -O2
reclaims it. It runs before install_local_binary's fork instrumentation,
which hardcodes mutable-global offsets and must run last — matching
bash/git/php/vim. Plain -O2 (not -all) honors the binary's declared
target_features; -all introduced exnref locals that break
wasm-fork-instrument.

Size

Shipped perl.wasm 7,291,919 → 6,822,373 bytes (−469,546 / −6.44%).

Note: ~3.06 MB of the shipped binary is fork-instrumentation overhead (perl
imports kernel_fork+kernel_execve), not dead code — so wasm-opt reclaims most
of the remaining non-instrumentation slack. -Oz was measured only 0.45%
smaller; -O2 chosen for interpreter throughput + convention parity.

Verification (on the instrumented recipe output, 6,822,373 B, 5 WPK exports)

  • runtime-smoke.ts: 9/9 PERL_RUNTIME_SMOKE_PASS
  • ext-smoke.ts: 21/21 (arithmetic, floats, strings, sprintf, regex incl.
    unicode//u, sort, hashes, pack/unpack, POSIX math, List::Util, refs/closures)
  • fork-smoke.ts: 5/5 — fork()+pipe+waitpid+exit, system(LIST) execve,
    open('-|',LIST). Confirms fork instrumentation survives the pass (runtime/ext
    smokes never fork).

The perl source compile is unchanged; validated instrument(raw)==shipped
byte-identical, and exercised the added wasm-opt -O2 + real install_local_binary
glue end-to-end. Full evidence in test-runs/kd-lfas/SUMMARY.md.

Stacking

Stacked on #821 (kd-k7zy, build-perl.sh rev 2). Base is the kd-k7zy branch;
retarget to main once #821 merges. The pass could alternatively be folded into
#821 if the maintainer prefers a single perl recipe PR.

Bead: kd-lfas.

🤖 Generated with Claude Code

brandonpayton and others added 2 commits July 2, 2026 02:22
build-perl.sh links with a load-bearing --no-gc-sections and applied no
post-link size pass, leaving dead code from the 30 curated static XS
extensions. Add a wasm-opt -O2 pass after the interpreter is re-collected and
BEFORE install_local_binary applies fork instrumentation. Fork instrumentation
hardcodes mutable-global offsets and must run last, so wasm-opt precedes it --
matching bash/git/php/vim. Plain -O2 (not -all) honors the binary's declared
target_features; -all introduced exnref locals that break wasm-fork-instrument.

Shipped perl.wasm 7,291,919 -> 6,822,373 bytes (-469,546 / -6.44%). ~3.06 MB of
the binary is fork-instrumentation overhead, so this reclaims most of the
non-instrumentation dead code. Verified on the instrumented recipe output:
runtime-smoke 9/9, extended functional battery 21/21, fork/system/pipe smoke
pass. -O2 over -Oz (only 0.45% smaller) for interpreter throughput + parity.

Bump build.toml revision 2 -> 3 (output bytes change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…pass

SUMMARY.md (measurement table, structural finding, decision), pass/fail/skip
outcome lists, and the ext-smoke.ts / fork-smoke.ts harnesses used to verify the
optimized binary. Evidence only; the .wasm artifacts are intentionally not
committed. fork-smoke.ts is the first fork/system coverage for perl (candidate
to promote via kd-gk6o CI wiring).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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