Skip to content

perf(contracts): document and benchmark size-optimized release profile#378

Open
noevidence1017 wants to merge 1 commit into
Miracle656:mainfrom
noevidence1017:perf/soroban-lto-size-bench-364
Open

perf(contracts): document and benchmark size-optimized release profile#378
noevidence1017 wants to merge 1 commit into
Miracle656:mainfrom
noevidence1017:perf/soroban-lto-size-bench-364

Conversation

@noevidence1017

Copy link
Copy Markdown
Contributor

Summary

Resolves the LTO / size-tier optimization work for the Soroban contracts and, per the acceptance criteria, records the before/after sizes and a reproducible benchmark.

The size-tuned [profile.release] (lto = true, codegen-units = 1, opt-level = "z", panic = "abort", symbol stripping) already exists in contracts/Cargo.toml. Because Cargo only applies [profile.*] from the workspace root, that is the correct location for it (member-crate profiles are ignored). This PR makes the optimization measurable and documented rather than implicit.

Changes

  • scripts/bench-wasm-size.sh — builds each contract for wasm32-unknown-unknown twice: once with the optimized profile and once with a naive release baseline (opt-level = 3, lto = false, codegen-units = 16, strip = "none"), applied purely through cargo --config overrides so nothing on disk is mutated. Prints a per-artifact size delta.
  • docs/wasm-size-optimization.md — explains each profile knob (including why strip = "symbols" is used instead of "debuginfo" — it is a strict superset — and why overflow-checks stays on for on-chain safety) and records the measured result.
  • contracts/Cargo.toml — inline rationale comments for every profile setting; values unchanged.

Before / after

invisible_wallet, wasm32-unknown-unknown, toolchain 1.85.0:

Build Size (bytes)
Naive release baseline 626,198
Optimized release 30,319
Saved 595,879 (95.2%)

Reproduce with scripts/bench-wasm-size.sh -p invisible-wallet. The saving (LTO dead-code elimination + symbol stripping + the "z" tier) is well beyond the ~30% target.

Tests

cargo test -p invisible-wallet → 49 passed; 0 failed.

Closes #364

Adds a reproducible WASM size benchmark and records the before/after
impact of the size-tuned [profile.release] (LTO, codegen-units=1,
opt-level="z", panic="abort", symbol stripping) that ships in
contracts/Cargo.toml.

- scripts/bench-wasm-size.sh builds each contract for
  wasm32-unknown-unknown with the optimized profile and again with a
  naive release baseline (via cargo --config overrides, mutating nothing
  on disk) and prints the per-artifact size delta.
- docs/wasm-size-optimization.md explains each profile knob (including
  why strip="symbols" is preferred over "debuginfo" and why
  overflow-checks stays on) and records the measured result.
- contracts/Cargo.toml gains inline rationale for every profile setting.

Measured (invisible_wallet, wasm32-unknown-unknown, toolchain 1.85.0):
naive release 626,198 B -> optimized 30,319 B = 95.2% smaller.

Tests still pass: cargo test -p invisible-wallet -> 49 passed; 0 failed.

Closes Miracle656#364
@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

@noevidence1017 is attempting to deploy a commit to the miracle656's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@noevidence1017 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Soroban LTO build optimization

1 participant