Skip to content

Commit dcd1f65

Browse files
authored
chore(aztec-nr): mark emit_event_in_public as #[inline_never] to shrink public dispatch (#23161)
## Summary Work towards resolving AztecProtocol/aztec-nr#35 - Mark `emit_event_in_public` `#[inline_never]` (and `unconstrained`, required by the attribute) so it stops being copied into every public call site. - Propagate `unconstrained` to `ContractSelfPublic::emit` so it can still call the helper. - Mirrors the existing precedent on `assert_is_initialized_public` (`aztec-nr/aztec/src/macros/functions/initialization_utils.nr:100`) from #22869 ## Bytecode impact Measured via `nargo compile --inliner-aggressiveness 0` + `bb aztec_process`, reading `public_dispatch` packed bytecode size on `public_fns_with_emit_repro_contract`: | State | AVM bytes | Δ | |-------------------|-----------|----------------| | Baseline | 5,576 | — | | `#[inline_never]` | 4,601 | -975 (-17.5%) | Roughly 65 bytes saved per emit call site across the 15 functions. Real contracts with many public functions emitting the same event shape should see the same per-site savings. ## Additional Context - `--inliner-aggressiveness` cannot achieve this on its own: for `public_dispatch` the noirc driver pins aggressiveness to 0 (`noir/noir-repo/compiler/noirc_driver/src/lib.rs:743-744`) - `ContractSelfPublic::emit` becoming `unconstrained` is a small surface change. All `#[external(\"public\")]` bodies are already unconstrained, so contract code calling `self.emit(...)` directly is unaffected
1 parent 28d61cd commit dcd1f65

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

noir-projects/aztec-nr/aztec/src/contract_self/contract_self_public.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<Storage, CallSelf, CallSelfStatic, CallInternal> ContractSelfPublic<Storage
118118
///
119119
/// Public event emission is achieved by emitting public transaction logs. A total of `N+1` fields are emitted,
120120
/// where `N` is the serialization length of the event.
121-
pub fn emit<Event>(&mut self, event: Event)
121+
pub unconstrained fn emit<Event>(&mut self, event: Event)
122122
where
123123
Event: EventInterface + Serialize,
124124
{

noir-projects/aztec-nr/aztec/src/event/event_emission.nr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ where
3535
}
3636

3737
/// Equivalent to `self.emit(event)`: see [`crate::contract_self::ContractSelfPublic::emit`].
38-
pub fn emit_event_in_public<Event>(context: PublicContext, event: Event)
38+
#[inline_never]
39+
pub unconstrained fn emit_event_in_public<Event>(context: PublicContext, event: Event)
3940
where
4041
Event: EventInterface + Serialize,
4142
{

0 commit comments

Comments
 (0)