Skip to content

feat(codegen): support narrow immutables#1003

Draft
DaniPopes wants to merge 1 commit into
mainfrom
dani/dynamic-immutable-sizes
Draft

feat(codegen): support narrow immutables#1003
DaniPopes wants to merge 1 commit into
mainfrom
dani/dynamic-immutable-sizes

Conversation

@DaniPopes

Copy link
Copy Markdown
Collaborator

Immutable references previously carried byte offsets through MIR and were forced into PUSH32 placeholders. This change gives each immutable a stable ImmutableId, records its MirType and TypeSize at the module boundary, and carries the fixed placeholder width through untyped EVM IR as the PUSH opcode and through assembly relocation metadata.

Deployment now patches PUSH1 through PUSH32 immediates without overwriting neighboring runtime bytes. Signed integers are sign-extended after narrow pushes, fixed bytes are restored to their left-aligned MIR representation, and the runtime copy location accounts for the 32-byte patch window. TypeSize also replaces raw integer widths in MIR values and related lowering helpers.

MIR and EVM IR parsing, validation, cost and layout estimates, optimization keys, and round trips have been updated around the typed IDs and sizes. Coverage includes lowering snapshots and deployment/runtime execution for unsigned, signed, fixed-bytes, address, default-width, and UDVT immutables.

Carry stable immutable IDs and TypeSize through MIR while encoding fixed placeholder widths in EVM IR and assembly relocations.

Patch narrow placeholders without overwriting adjacent runtime bytes, and normalize signed and fixed-bytes loads after PUSH<N>.
@github-actions

Copy link
Copy Markdown
Contributor

Codegen benchmark

bench gas (vs main) solc size (vs main) solc
factorial 209,949 (~0%) 224,168 (✅ +6.77%) 213B (~0%) 226B (✅ +6.10%)
counter 199,086 (~0%) 217,859 (✅ +9.43%) 200B (~0%) 228B (✅ +14.00%)
sum-array 185,503 (~0%) 229,597 (✅ +23.77%) 182B (~0%) 209B (✅ +14.84%)
arithmetic 140,122 (~0%) 158,924 (✅ +13.42%) 214B (~0%) 243B (✅ +13.55%)
openzeppelin-erc20-mock 381,023 (~0%) 381,297 (✅ +0.07%) 1,709B (~0%) 1,864B (✅ +9.07%)
openzeppelin-vesting-wallet 384,032 (~0%) 382,672 (❌ -0.35%) 2,333B (✅ -5.85%) 2,064B (❌ -11.53%)
nitro-one-step-proof 348,152 (~0%) 366,604 (✅ +5.30%) 14,560B (~0%) 10,806B (❌ -25.78%)
aave-l2-encoder 589,021 (~0%) 635,207 (✅ +7.84%) 3,069B (✅ -4.78%) 3,339B (✅ +8.80%)
lilweb3-ens 463,020 (~0%) 468,104 (✅ +1.10%) 419B (~0%) 665B (✅ +58.71%)
lilweb3-flashloan 489,192 (~0%) 491,208 (✅ +0.41%) 1,628B (✅ -2.16%) 1,606B (❌ -1.35%)
lilweb3-fractional 330,921 (~0%) 331,397 (✅ +0.14%) 5,537B (❌ +1.22%) 5,622B (✅ +1.54%)
maple-erc20 445,437 (~0%) 446,566 (✅ +0.25%) 2,199B (✅ -1.39%) 2,678B (✅ +21.78%)
Peak RSS
compiler benches average peak RSS maximum peak RSS maximum bench
solc 12 20.0 MiB 39.6 MiB nitro-one-step-proof
solar 12 20.0 MiB 22.3 MiB nitro-one-step-proof

Per-benchmark peak RSS

bench solc peak solar peak Solar vs solc
factorial 14.6 MiB 20.2 MiB ❌ +38.11%
counter 14.4 MiB 20.2 MiB ❌ +40.92%
sum-array 14.4 MiB 20.1 MiB ❌ +40.18%
arithmetic 14.7 MiB 19.9 MiB ❌ +35.21%
openzeppelin-erc20-mock 20.4 MiB 19.5 MiB ✅ -4.50%
openzeppelin-vesting-wallet 19.8 MiB 20.0 MiB ❌ +1.15%
nitro-one-step-proof 39.6 MiB 22.3 MiB ✅ -43.68%
aave-l2-encoder 25.4 MiB 20.2 MiB ✅ -20.58%
lilweb3-ens 15.4 MiB 18.9 MiB ❌ +23.16%
lilweb3-flashloan 17.5 MiB 19.2 MiB ❌ +9.46%
lilweb3-fractional 23.5 MiB 19.7 MiB ✅ -16.29%
maple-erc20 20.4 MiB 19.5 MiB ✅ -4.76%

@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 5.41%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 77 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
Counter/lex 12 µs 11.4 µs +5.41%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing dani/dynamic-immutable-sizes (43c2f66) with main (341e603)

Open in CodSpeed

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