Repository navigation
Commit 7d3d314
committed
perf: keep each value stack's height outside its Vec
The height of a value-stack lane is its own field, over a Vec that holds
every slot the lane has reached. Slots above the height hold stale values
that are written before they are read again.
The tail-call handlers can then pass the height between them in a register
and write it back without unsafe code.
Entering a function writes its locals, and its operand-stack reservation
if that is at most 64 slots, so later entries at that height compare once.
A larger reservation stays capacity, and a push writes each slot the first
time it reaches it (on the tail-call build with push_within_capacity, which
makes no call), so a function whose deep branch rarely runs keeps no pages
for it. With 64 stores of a module whose untaken branch declares a
30000-deep i64 stack, each store keeps next's footprint (35 KB on macOS,
16-19 KB on glibc) instead of 273 KB and 250 KB.
v128.any_true and i8x16.all_true test the vector with integer arithmetic:
LLVM scalarized their iterator forms once pushes gained that path.
Only builds with debug assertions check indices against the height. CI
also runs the tests optimized with them, keeping the release profile's
wrapping arithmetic.
Entering a function zeroes one or two locals with direct stores, and only
the ones in between with memset.1 parent 3a1723e commit 7d3d314
4 files changed
Lines changed: 204 additions & 48 deletions
File tree
- .github/workflows
- crates/tinywasm/src
- interpreter
- simd
- stack
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
49 | 54 | | |
50 | 55 | | |
51 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
502 | 506 | | |
503 | 507 | | |
504 | 508 | | |
| |||
0 commit comments