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

Use Vec::with_capacity() to avoid reallocations with repeated push()'s #34242

Merged
merged 1 commit into from
Nov 28, 2023

Conversation

steviez
Copy link
Contributor

@steviez steviez commented Nov 28, 2023

Problem

The length of tx_cells is known at the start, so we can size the Vec appropriately off the bat to avoid the reallocations.

Summary of Changes

vec![] ==> Vec::with_capacity()

The length of tx_cells is known before the loop that populates it, so we
can appropriately allocate the Vec immediatley to avoid any
reallocations.
Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Merging #34242 (4665324) into master (b741c9c) will increase coverage by 0.0%.
The diff coverage is 0.0%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #34242   +/-   ##
=======================================
  Coverage    81.9%    81.9%           
=======================================
  Files         819      819           
  Lines      219387   219387           
=======================================
+ Hits       179690   179768   +78     
+ Misses      39697    39619   -78     

@steviez steviez marked this pull request as ready for review November 28, 2023 16:34
Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Thanks!

@steviez steviez merged commit 4d2018f into solana-labs:master Nov 28, 2023
32 checks passed
@steviez steviez deleted the bt_prealloc_vec branch November 28, 2023 17:26
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