Repository navigation
Commit fe27adf
authored
perf: grow the value stack out of line (#57)
First of a three-PR stack on `next` (`785be0e`), each on top of the
previous one with individual wins that combine nicely:
1. #57 **perf: grow the value stack out of line** (this PR)
2. #58 perf: inline the fused binop and compare helpers
3. #59 perf: reserve each function's operand stack on entry
`Stack::push` now checks `len == capacity` itself and hands the full
case to a `#[cold] #[inline(never)] push_grow`, which keeps the existing
overflow check and growth. After that check `Vec::push` can no longer
reach its own growth path, so the allocator call leaves the instruction
handlers. It was inlined into every handler that pushes, and the call
made those handlers save and restore four pairs of callee-saved
registers on every execution, even though the default config's stacks
are fixed and never grow. `LocalGet32`'s hot path goes from 57 to 37
instructions on aarch64.
No behavior change: fixed stacks still trap at capacity, and dynamic
stacks still grow up to `max_size`.
**iPhone 12 efficiency cores** (A14 Icestorm, `.utility` QoS). XCode 27
PMU template for low-level CPU stats. 16 benchmark rows, 5 launches per
build, interleaved with the other builds of the stack; cycles and
instructions per call, geomean against `next` as of `b45a98a`:
| | cycles | instructions | rows faster |
|---|---:|---:|---:|
| this PR vs `next` | **−4.1 %** | −3.5 % | 16/16 |
**Checks** on this branch: tinywasm's CI matrix run on my local M4 Mac:
`cargo test --workspace` and `cargo test --workspace --examples` with
`--features tinywasm/nightly-tail-calls`, each with and without default
features1 parent 785be0e commit fe27adf
1 file changed
Lines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
65 | 72 | | |
66 | 73 | | |
67 | 74 | | |
| |||
0 commit comments