Skip to content

Commit 39e3490

Browse files
authored
Use a SmallVector in MergeBlocks [NFC] (#5594)
This makes the pass 2-3% faster in some measurements I did locally. Noticed when profiling for #5561 (comment) Helps #4165
1 parent 0f9c9b0 commit 39e3490

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/passes/MergeBlocks.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <ir/iteration.h>
7878
#include <ir/utils.h>
7979
#include <pass.h>
80+
#include <support/small_vector.h>
8081
#include <wasm-builder.h>
8182
#include <wasm.h>
8283

@@ -330,9 +331,13 @@ static void optimizeBlock(Block* curr,
330331
}
331332
// There is something to do!
332333
bool keepingPart = keepStart < keepEnd;
333-
// Create a new merged list, and fill in the code before the
334-
// child block we are merging in. TODO better efficiency
335-
ExpressionList merged(module->allocator);
334+
// Create a new merged list, and fill in the code before the child block
335+
// we are merging in. It is efficient to use a small vector here because
336+
// most blocks are fairly small, and this way we copy once into the arena
337+
// we use for Block lists a single time at the end (arena allocations
338+
// can't be freed, so any temporary allocations while we add to the list
339+
// would end up wasted).
340+
SmallVector<Expression*, 10> merged;
336341
for (size_t j = 0; j < i; j++) {
337342
merged.push_back(list[j]);
338343
}
@@ -383,7 +388,7 @@ static void optimizeBlock(Block* curr,
383388
}
384389
}
385390
}
386-
list.swap(merged);
391+
list.set(merged);
387392
more = true;
388393
changed = true;
389394
break;

0 commit comments

Comments
 (0)