You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch (#23464)
## Summary
Additional work towards resolving
AztecProtocol/aztec-nr#35
- In `generate_public_dispatch`, count parameter-type signatures across
the contract public functions. When at least `EXTRACTION_THRESHOLD` (4)
functions share a signature, emit one `#[inline_never]`
`__aztec_nr_internals__unpack_arguments_<N>` helper that does the
`calldata_copy` + per-parameter `stream_deserialize` once, and rewrite
those dispatch arms to call it.
- Signatures below the threshold keep the previous inline shape, so we
do not pay CALL/RET overhead on call sites that would not recoup it.
- Follows the same pattern as
#23161, but targets
the calldata-deserialization boilerplate the dispatch macro inlines into
every arm rather than user-written helpers.
## Bytecode impact
Measured via `nargo compile --inliner-aggressiveness 0` + `bb
aztec_process`, reading `public_dispatch` packed bytecode:
| Contract | Baseline | Post | Δ |
|---------------------------------------|----------|--------|----------------|
| `public_fns_with_emit_repro_contract` | 4,601 | 4,227 | -374 (-8.1%) |
| `avm_test_contract` | 51,333 | 51,048 | -285 (-0.55%) |
The repro contract is the same one used in #23161, so the delta stacks
on top of that one. Real contracts with many public functions sharing
parameter shapes is where we see savings from this change.
## Additional Context
- The threshold is a single share-count knob for now. The real
break-even depends on per-site `stream_deserialize` size (one `Field`
arg vs. e.g. `(AztecAddress, U128, PartialUintNote)`), but a single
threshold keeps the macro readable; we can size helpers against per-site
savings later if needed.
- Follow-up:
[F-675](https://linear.app/aztec-labs/issue/F-675/centralize-validation-for-aztec-nr-macro-generated-internal-function)
tracks centralizing validation for aztec-nr macro-generated internal
names. The generated-name collision class predates this PR, and the new
unpack helper names are one specific instance.
Copy file name to clipboardExpand all lines: noir-projects/contract-snapshots/tests/snapshots/compile_failure/public_function_selector_collision/snapshots__stderr.snap
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,10 @@ error: Public function selector collision detected between functions 'fn_selecto
14
14
2: aztec
15
15
at <repo>/noir-projects/aztec-nr/aztec/src/macros/aztec.nr:169:27
16
16
3: generate_public_dispatch
17
-
at <repo>/noir-projects/aztec-nr/aztec/src/macros/dispatch.nr:20:19
17
+
at <repo>/noir-projects/aztec-nr/aztec/src/macros/dispatch.nr:52:19
18
18
4: [T]::map
19
19
at std/vector.nr:67:33
20
20
5: generate_public_dispatch
21
-
at <repo>/noir-projects/aztec-nr/aztec/src/macros/dispatch.nr:32:13
21
+
at <repo>/noir-projects/aztec-nr/aztec/src/macros/dispatch.nr:64:13
Copy file name to clipboardExpand all lines: noir-projects/contract-snapshots/tests/snapshots/expand/avm_gadgets_test_contract/snapshots__expanded.snap
0 commit comments