Skip to content

chore(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch#23464

Open
vezenovm wants to merge 1 commit into
merge-train/fairiesfrom
mv/macros-unpack-per-sig-helper
Open

chore(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch#23464
vezenovm wants to merge 1 commit into
merge-train/fairiesfrom
mv/macros-unpack-per-sig-helper

Conversation

@vezenovm
Copy link
Copy Markdown
Contributor

@vezenovm vezenovm commented May 21, 2026

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 chore(aztec-nr): mark emit_event_in_public as #[inline_never] to shrink public dispatch #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 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.

@vezenovm vezenovm requested a review from nventuro as a code owner May 21, 2026 11:03
@vezenovm vezenovm changed the title chore(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch perf(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch May 21, 2026
@vezenovm vezenovm changed the title perf(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch chore(aztec-nr): extract per-signature calldata unpack helpers to shrink public_dispatch May 21, 2026
@vezenovm vezenovm requested review from benesjan, mverzilli and nchamo May 21, 2026 11:57
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