Skip to content

Commit 44cd751

Browse files
authored
[NFC] Optimize ArrayNew zero construction (#5722)
All array elements have the same type, so we can construct a single zero and just copy it. This makes ArrayNew of large arrays 2x faster. I also experimented with putting Literal::makeZero in a header, in hopes of inlining leading to licm helping here, but that did not help at all unfortunately, at least not in gcc.
1 parent 71a1512 commit 44cd751

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/wasm-interpreter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,8 +1642,9 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
16421642
}
16431643
Literals data(num);
16441644
if (curr->isWithDefault()) {
1645+
auto zero = Literal::makeZero(element.type);
16451646
for (Index i = 0; i < num; i++) {
1646-
data[i] = Literal::makeZero(element.type);
1647+
data[i] = zero;
16471648
}
16481649
} else {
16491650
auto field = curr->type.getHeapType().getArray().element;

0 commit comments

Comments
 (0)