From f04340b1251ec5075228faecd5927e7a586af082 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:36:40 -0500 Subject: [PATCH] move allocation out of critical section and estimate capacity better (#18450) --- runtime/src/accounts_index.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 3f22845c37..25448c0a74 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1382,7 +1382,9 @@ impl, ) -> (Vec, u64) { - let expected_items_per_bin = item_len * 2 / BINS; // big enough so not likely to re-allocate, small enough to not over-allocate + // big enough so not likely to re-allocate, small enough to not over-allocate by too much + // this assumes the largest bin contains twice the expected amount of the average size per bin + let expected_items_per_bin = item_len * 2 / BINS; let mut binned = (0..BINS) .into_iter() .map(|pubkey_bin| (pubkey_bin, Vec::with_capacity(expected_items_per_bin))) @@ -1401,9 +1403,12 @@ impl