Skip to content

fix: strip motoko:stable-types section from wasm under --enhanced-migration#6073

Draft
alexandru-uta wants to merge 2 commits into
masterfrom
alex/enh-mig-optimizations
Draft

fix: strip motoko:stable-types section from wasm under --enhanced-migration#6073
alexandru-uta wants to merge 2 commits into
masterfrom
alex/enh-mig-optimizations

Conversation

@alexandru-uta
Copy link
Copy Markdown
Contributor

@alexandru-uta alexandru-uta commented Apr 30, 2026

Strips the motoko:stable-types custom section from the wasm whenever --enhanced-migration is active. The section grows linearly with the migration chain (~280 KB at length 200, ~1.4 MB at length 1000), duplicates the .most file content emitted under --stable-types, and under enhanced orthogonal persistence is redundant for upgrade safety because the runtime system already enforces stable-type compatibility at upgrade time. Long migration chains were pushing the wasm past the IC's ~1 MB metadata limits with this section alone.

Behaviour preserved

  • Compile-time validate_stab_sig still runs (reads from stable_types_text).
  • --stable-types still writes .most next to the wasm (reads from stable_types_text).
  • The JS API (js_compile_wasm) still returns the stable signature string.
  • customModuleDecode mirrors the in-section text into stable_types_text on round-trip, so any consumer that loads a wasm that does embed the section still works unchanged.
  • Classical persistence and non---enhanced-migration builds keep embedding the section; behaviour there is unchanged.

Made with Cursor

…ration

The `motoko:stable-types` custom section grows linearly with the migration
chain (~280 KB at length 200, ~1.4 MB at length 1000) and duplicates the
content of the `.most` file emitted under `--stable-types`. With enhanced
orthogonal persistence the runtime system already enforces stable-type
compatibility at upgrade time, so the embedded section is redundant for
correctness and is now stripped from the wasm under `--enhanced-migration`.

To keep compile-time validation (`validate_stab_sig`) and the `.most` file
emit working when the wasm section is suppressed, the raw signature text
is now carried in a separate, always-populated `stable_types_text` field
on `motoko_sections`. This also fixes a pre-existing footgun on the
classical codegen path where `--omit-metadata motoko:stable-types`
silently disabled validation and the `.most` emit.

The 3 lines of new logic live in the `metadata` helper in
`compile_enhanced.ml`; everything else is plumbing for the decoupling.

Verified with the full motoko test suite (1,221 tests across `fail/`,
`run/`, `trap/`, `run-drun/`, `cmp/`) and against the long-rich
benchmark at N=200/500/1000: wasm size shrinks by exactly the section
size at every chain length, `.most` files are written with equivalent
content, and compile time is unchanged.

Made-with: Cursor
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Comparing from a6ea4d2 to a0ccfcb:
The produced WebAssembly code seems to be completely unchanged.
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

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