Skip to content

perf: replace heap allocations with stack arrays in logup inner loops#161

Merged
TomWambsgans merged 1 commit intoleanEthereum:mainfrom
jiayaoqijia:fix/logup-stack-arrays
Mar 1, 2026
Merged

perf: replace heap allocations with stack arrays in logup inner loops#161
TomWambsgans merged 1 commit intoleanEthereum:mainfrom
jiayaoqijia:fix/logup-stack-arrays

Conversation

@jiayaoqijia
Copy link
Contributor

Fixes #154.

Replaces two Vec heap allocations with stack-allocated fixed-size arrays in the hot inner loops of prove_generic_logup:

  1. Bytecode lookup denominator (line 119): Vec::with_capacity(1 + N_INSTRUCTION_COLUMNS)[F::ZERO; N_INSTRUCTION_COLUMNS + 1] — matching the existing pattern at lines 88-90.

  2. Bus denominator (lines 147-153): .collect::<Vec<_>>()[F::ZERO; N_INSTRUCTION_COLUMNS] with explicit length slice &bus_data[..bus.data.len()]. All bus data lengths are ≤ 4 (verified across all table implementations), well within the N_INSTRUCTION_COLUMNS = 12 bound.

  3. Bytecode columns collection (line 111): .collect::<Vec<_>>() → slice reference, avoiding an unnecessary Vec allocation.

These allocations occur inside par_iter_mut().for_each() closures, meaning they execute once per row of the trace — potentially millions of times. Stack arrays eliminate per-iteration allocator pressure and improve cache locality.

@TomWambsgans TomWambsgans merged commit 24cb6ab into leanEthereum:main Mar 1, 2026
3 checks passed
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.

Heap allocations in Logup inner loop add ~10-20% overhead

2 participants