Skip to content

Commit 6716fdd

Browse files
agape1225aduh95
authored andcommitted
src: reserve shared_array_buffers capacity in Message::Deserialize
shared_array_buffers grows via repeated push_back() while iterating shared_array_buffers_, even though shared_array_buffers_.size() is already known before the loop starts and is an exact count of how many items will be pushed (one per iteration, unconditionally). This reserves capacity upfront to avoid the repeated allocate/copy/ free cycle that happens each time capacity is exceeded, mirroring the existing array_buffers.reserve() in the sibling Message::Serialize(). Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com> PR-URL: #65304 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a88c0d3 commit 6716fdd

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎src/node_messaging.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ MaybeLocal<Value> Message::Deserialize(Environment* env,
190190
transferables_.clear();
191191

192192
LocalVector<SharedArrayBuffer> shared_array_buffers(env->isolate());
193+
shared_array_buffers.reserve(shared_array_buffers_.size());
193194
// Attach all transferred SharedArrayBuffers to their new Isolate.
194195
for (uint32_t i = 0; i < shared_array_buffers_.size(); ++i) {
195196
Local<SharedArrayBuffer> sab =

0 commit comments

Comments
 (0)