Skip to content

perf: remove unnecessary heap allocs#148

Open
malik672 wants to merge 1 commit intoleanEthereum:mainfrom
malik672:opt
Open

perf: remove unnecessary heap allocs#148
malik672 wants to merge 1 commit intoleanEthereum:mainfrom
malik672:opt

Conversation

@malik672
Copy link

@malik672 malik672 commented Feb 28, 2026

  • Replace push/extend_from_slice loops with pre-sized set_len + offset writes across xmss and rec_aggregation
  • Replace .to_vec() / .concat().try_into() with copy_from_slice into stack arrays
  • Pre-allocate trace vectors with known capacity

this shows improvement on 1000sig aggregation (120 → 137 sig/s)

pub fn to_big_endian_bits(value: usize, bit_count: usize) -> Vec<bool> {
  (0..bit_count).rev().map(|i| (value >> i) & 1 == 1).collect()
}

pub fn to_big_endian_in_field<F: Field>(value: usize, bit_count: usize) -> Vec<F> {
  (0..bit_count)
      .rev()
      .map(|i| F::from_bool((value >> i) & 1 == 1))
      .collect()
}

can be done here too

@TomWambsgans
Copy link
Collaborator

Hi, thanks for your PR. I believe the "120 → 137 sig/s" is likely a statistical fluctuation, since this part of the code should represent a negligible portion of prover's work. That's why I am a bit reluctant to add 50 LoC for an unclear benefit. But I think one can still optimize this without adding all these lines, simply by adding Vec::with_capacityfor instance, what do you think?

@malik672
Copy link
Author

malik672 commented Mar 2, 2026

Hi, thanks for your PR. I believe the "120 → 137 sig/s" is likely a statistical fluctuation, since this part of the code should represent a negligible portion of prover's work. That's why I am a bit reluctant to add 50 LoC for an unclear benefit. But I think one can still optimize this without adding all these lines, simply by adding Vec::with_capacityfor instance, what do you think?

Thanks
true the prover is the main bottleneck, coming will recheck

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.

2 participants