Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Perf] Use SmallVec for additional temporary allocations #4

Open
wants to merge 7 commits into
base: mainnet-staging
Choose a base branch
from

Conversation

ljedrz
Copy link
Collaborator

@ljedrz ljedrz commented May 30, 2024

This is a follow-up to #3 which includes the same approach, but in scenarios that require some additional setup.

The first commit introduces a new trait, VecLike, which applies to both Vec<bool> and SmallVec<[bool; N]>, and allows us to use the latter in ToBits operations that are currently restricted to the former.

While the new trait is quite trivial, it does require a bit of boilerplate (the Extend::extend, VecLike::extend_from_slice etc.) for disambiguation. The upside is that together with the other linked PR, there are clear performance benefits to doing so:

  • total allocations are down ~12%
  • temporary allocations are down by ~13% (in terms of their share of total allocations)
  • while this measurement isn't consistent, the RSS may be reduced by up to ~7%

(measured in a --dev node in 15-minute local runs from scratch)

/// Writes `self` into the given vector as a boolean array in little-endian order.
fn write_bits_le(&self, vec: &mut Vec<bool>);
fn write_bits_le<T: VecLike>(&self, vec: &mut T);

/// Writes `self` into the given vector as a boolean array in big-endian order.
fn write_bits_be(&self, vec: &mut Vec<bool>);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this wasn't extended to write_bits_be, as those haven't been showing up in heap profiles, and the implementation of indexing that it would have to involve is a little bit tricky

@vicsn vicsn force-pushed the mainnet-staging branch from 74a4378 to d48f6fb Compare June 5, 2024 12:33
ljedrz added 7 commits June 6, 2024 13:11
Signed-off-by: ljedrz <ljedrz@gmail.com>
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
Signed-off-by: ljedrz <ljedrz@users.noreply.github.com>
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