Skip to content

Do not restart the blockparam_ins walk for every block of a range - #287

Open
bytemaster wants to merge 1 commit into
bytecodealliance:mainfrom
gofractally:blockparam-walk-per-range
Open

bytemaster wants to merge 1 commit into
bytecodealliance:mainfrom
gofractally:blockparam-walk-per-range

Conversation

@bytemaster

Copy link
Copy Markdown

Fixes #286, which has the reproduction, the measurements and the argument that the output is unchanged.

apply_allocations_and_insert_moves restarted its walk of blockparam_ins from the buffered cursor for every block a live range covers, so a block parameter with T predecessors that stays live across B later blocks cost T × B steps. This is the part of #274 that remains after #281. The change moves the walk's index out of the per-block loop so that it starts once per range and continues from block to block; within a range blocks are visited in increasing order and the entries are sorted by (vreg, block), so each block's walk collects the same entries and ends at the same index as before.

  • cargo test --all --all-features passes.
  • Differential run of the fuzzing::func generator against main: 184,157 functions, equal Output or the same error for every one, checker accepts.
  • Wasmtime compiled modules are byte-identical with and without the change; 512 locals × 4,096 br_table targets, two merges: 8.11 s → 1.03 s.

🤖 Generated with Claude Code

apply_allocations_and_insert_moves walks blockparam_ins, sorted by
(to_vreg, to_block), once for every block whose entry a live range
covers, and each of those walks started again from the cursor buffered
for the range. Ranges of one vreg can overlap, so the cursor must be
re-read per range, but within one range blocks are visited in increasing
order: everything a walk steps over is below the key of every later
block and cannot match it. Restarting per block therefore only repeated
work: a block parameter with T predecessors that stays live across B
later blocks cost T * B steps, and L such parameters L * T * B. With two
merge points of T edges in one function, B is T for the parameters of
the first.

Carry the walk's position from block to block within a range. The
entries collected and the cursor value handed to PrevBuffer are the
same in every case, including the case in which the buffered cursor
has already passed a block's entries, so the output is unchanged.

bytecodealliance#281 removed the other half of the problem, the cursor that a vreg with
a single range left behind for all later vregs. With both, the walk is
linear in the number of entries plus the number of (range, block) pairs.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: move insertion is quadratic in a block parameter's predecessors × the blocks it stays live across

1 participant