Skip to content

Commit

Permalink
Merge pull request #2327 from AntelopeIO/avoid_linear_resize
Browse files Browse the repository at this point in the history
Perf issue: avoid vector copy at each insertion.
  • Loading branch information
greg7mdp authored Mar 20, 2024
2 parents 3868b80 + 365ef48 commit 13b1c03
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libraries/chain/transaction_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <eosio/chain/deep_mind.hpp>

#include <chrono>
#include <bit>

namespace eosio { namespace chain {

Expand Down Expand Up @@ -708,11 +709,12 @@ namespace eosio { namespace chain {
{
uint32_t new_action_ordinal = trace->action_traces.size() + 1;

trace->action_traces.reserve( new_action_ordinal );
trace->action_traces.reserve( std::bit_ceil(new_action_ordinal) ); // bit_ceil to avoid vector copy on every reserve call.

const action& provided_action = get_action_trace( action_ordinal ).act;

// The reserve above is required so that the emplace_back below does not invalidate the provided_action reference.
// The reserve above is required so that the emplace_back below does not invalidate the provided_action reference,
// which references an action within the `trace->action_traces` vector we are appending to.

trace->action_traces.emplace_back( *trace, provided_action, receiver, context_free,
new_action_ordinal, creator_action_ordinal,
Expand Down

0 comments on commit 13b1c03

Please sign in to comment.