Skip to content

perf(trampoline): build vp-shim with build-std to shrink it to 72KB - #2465

Draft
fengmk2 wants to merge 2 commits into
mainfrom
perf/trampoline-build-std
Draft

perf(trampoline): build vp-shim with build-std to shrink it to 72KB#2465
fengmk2 wants to merge 2 commits into
mainfrom
perf/trampoline-build-std

Conversation

@fengmk2

@fengmk2 fengmk2 commented Aug 16, 2026

Copy link
Copy Markdown
Member

Shrinks the Windows shim vp-shim.exe from 213KB to 72KB with zero source changes.

The size was set by the precompiled std: lang_start init, panic formatting, and backtrace support stay linked no matter what the crate code does, and opt-level = "z" cannot remove code a prebuilt rlib already contains. The fix recompiles std under the crate's own size profile:

  • crates/vp_trampoline leaves the workspace (cargo ignores panic in per-package profile overrides, so the crate needs its own profile with panic = "immediate-abort"; uv excludes uv-trampoline for the same reason).
  • A crate-local .cargo/config.toml enables -Zbuild-std and keeps artifacts in the repo-root target/, so CI steps, the snapshot runner, and install-global-cli find vp-shim.exe in the same place as before.
  • rust-toolchain.toml adds the rust-src component. The repo already pins the nightly toolchain, so no toolchain change.
  • Every former cargo build -p vp_trampoline call site (bootstrap-cli, justfile, both CI composite actions) now builds from the crate directory so the config applies. The root Cargo.lock drops the stale vp_trampoline entry, which --locked commands require.

Measured with cargo-xwin:

Target Before After
x86_64-pc-windows-msvc 212,992 B 73,728 B
aarch64-pc-windows-msvc 190,976 B 71,168 B

For reference: uv-trampoline ships 45KB, Scoop's default C shim is 136KB. The trampoline RFC now records the full measured variant table, including a verified 6.6KB raw-Win32 recipe and its gotchas (the atexit pull on current nightlies under #![no_main], the required subsystem attribute, the +crt-static size trap), as reference for future size work.

Verified locally: release builds for both Windows targets and the host, crate clippy/fmt/test, cargo metadata --locked on the workspace, and dry-runs of the edited just recipes. The trampoline source is unchanged, so the Windows CI leg (PTY snapshot suite) is the remaining behavior gate; the vp-binary-size workflow should show the drop on this PR.

Move crates/vp_trampoline out of the workspace: cargo ignores `panic` in
per-package profile overrides, so the crate needs its own release profile
with panic = "immediate-abort". A crate-local .cargo/config.toml enables
build-std, which recompiles std under the size profile and compiles out
the panic formatting, unwinding, and backtrace machinery. The source is
unchanged.

vp-shim.exe: 212,992 B to 73,728 B on x86_64-pc-windows-msvc,
190,976 B to 71,168 B on aarch64-pc-windows-msvc.

The crate config keeps artifacts in the repo-root target/ directory, so
CI steps, the snapshot runner, and install-global-cli find vp-shim.exe in
the same place as before. Every former `cargo build -p vp_trampoline`
call site now builds from the crate directory so the config applies.
rust-toolchain.toml adds the rust-src component (build-std needs the std
sources). The root Cargo.lock drops the stale vp_trampoline entry, which
--locked commands require. The trampoline RFC records the measured
variant table down to a 7KB raw-Win32 recipe for future size work.
@netlify

netlify Bot commented Aug 16, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit 9cf73b7
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a81a8cdcb956000088bcff9

@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Native binary sizes (9cf73b7)

Final release artifacts built by the canonical build-upstream and build-windows-cli actions.

Artifact Format Base PR Change
vp (Linux x64) Binary 10.67 MiB 10.68 MiB +4.00 KiB (+0.04%)
vp (Linux x64) gzip -9 4.62 MiB 4.62 MiB +566 B (+0.01%)
NAPI (Linux x64) Binary 32.02 MiB 32.03 MiB +8.00 KiB (+0.02%)
NAPI (Linux x64) gzip -9 12.61 MiB 12.61 MiB -476 B (-0.00%)
vp (macOS ARM64) Binary 7.98 MiB 7.98 MiB +16 B (+0.00%)
vp (macOS ARM64) gzip -9 4.03 MiB 4.03 MiB +312 B (+0.01%)
NAPI (macOS ARM64) Binary 39.68 MiB 39.68 MiB +32 B (+0.00%)
NAPI (macOS ARM64) gzip -9 16.92 MiB 16.92 MiB +893 B (+0.01%)
vp (Windows x64) Binary 8.55 MiB 8.56 MiB +7.00 KiB (+0.08%)
vp (Windows x64) gzip -9 3.73 MiB 3.73 MiB +1.87 KiB (+0.05%)
NAPI (Windows x64) Binary 26.89 MiB 26.90 MiB +8.50 KiB (+0.03%)
NAPI (Windows x64) gzip -9 10.68 MiB 10.69 MiB +1.79 KiB (+0.02%)
Trampoline (Windows x64) Binary 205.00 KiB 72.00 KiB -133.00 KiB (-64.88%)
Trampoline (Windows x64) gzip -9 99.00 KiB 39.79 KiB -59.20 KiB (-59.80%)
Installer (Windows x64) Binary 4.47 MiB 4.47 MiB +5.50 KiB (+0.12%)
Installer (Windows x64) gzip -9 2.09 MiB 2.09 MiB +1.48 KiB (+0.07%)

The Build Windows tests archive step enumerates crates/*/ and passed
-p vp_trampoline, which is no longer a workspace member; skip it like
the justfile test recipe does (its only test module is unix-only, so it
has nothing to contribute to the Windows archive). Also apply oxfmt
0.63.0 to the RFC tables, which vp check flagged on the CLI E2E jobs.
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