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

load_addresses performance #3182

Merged
merged 2 commits into from
Oct 17, 2024
Merged

Conversation

apfitzge
Copy link

Problem

  • Bank::load_addresses and Bank::load_addresses_from_ref allocate inefficiently:
    • Allocates (up to) 2 vecs for LoadedAddresses for each MessageAddressTableLookup in the message
    • Then combines these LoadedAddresses via collect into a single LoadedAddresses

Summary of Changes

  • Create a LoadedAddresses up front, and load addresses into that table.
    • This still may allocate multiple times as we expand.

Fixes #

@apfitzge apfitzge self-assigned this Oct 15, 2024
@@ -51,22 +51,20 @@ impl Bank {
.map_err(|_| AddressLoaderError::SlotHashesSysvarNotFound)?;

let mut deactivation_slot = u64::MAX;
let loaded_addresses = address_table_lookups
.map(|address_table_lookup| {
let mut loaded_addresses = LoadedAddresses::default();
Copy link
Author

Choose a reason for hiding this comment

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

We could, with some work in higher-level functions, pre-allocate the space for this.

@apfitzge apfitzge marked this pull request as ready for review October 16, 2024 14:01
@apfitzge apfitzge requested a review from jstarry October 16, 2024 14:01
slot_hashes,
)?;

// Append to the loaded addresses.
Copy link

Choose a reason for hiding this comment

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

Before appending we should reserve space for the number of pushed elements to avoid potentially triggering multiple allocations while pushing a lot of elements.

Copy link
Author

Choose a reason for hiding this comment

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

👍 used reserve so it will only allocate if necessary.

@apfitzge apfitzge merged commit d300f37 into anza-xyz:master Oct 17, 2024
50 checks passed
@apfitzge apfitzge deleted the loaded_addresses_collect branch October 17, 2024 15:55
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
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