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 issue: avoid vector copy at each insertion. #2327

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 insertion

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
Loading