Skip to content

perf: callee previews, type fixed point, guard crossings and per-query scans (-38% on the full dataset) - #899

Open
sjkim1127 wants to merge 8 commits into
mainfrom
perf/callee-summary-reuse
Open

sjkim1127 wants to merge 8 commits into
mainfrom
perf/callee-summary-reuse

Conversation

@sjkim1127

@sjkim1127 sjkim1127 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Four output-preserving speed changes, measured on the full DecBench dataset (noelo-lab/decbench-dataset, config full), stripped binaries, all listed functions per binary in one decomp --addresses-file call, fixed every-10th subset of 81 binaries / 7,969 functions. Every step was checked for identical code on all 7,969 functions.

commit what wall CPU
100674d skip the stable-prefix callee preview when the prefix decodes to the whole body 133.8 -> 127.5 s 721 -> 675 s
f4e044c compute a callee summary once when workers miss the same key concurrently 125.7 -> 123.0 s 669 -> 626 s
74451cf skip the dead-receiver liveness walk when no receiver qualifies 123.1 -> 116.6 s 629 -> 614 s
0c9bfd5 stop the type fixed point when a round returns to its starting state 115.5 -> 97.1 s 613 -> 507 s
15502f0 tabulate guard truth tables 64 rows per word, atoms resolved once 93.8 -> 92.6 s 498 -> 483 s
8e86a61 three per-query scans: fuse-boundary copies, per-candidate BFS, candidate def keys 97.7 -> 89.4 s 480 -> 451 s
32f3b45 seed render options once per binary snapshot; reuse derived register maps 85.0 -> 84.7 s 451 -> 443 s
228f6ec decide out-of-SSA guard crossings a guard block at a time 85.0 -> 80.7 s 448 -> 431 s

Cumulative, main after #883 vs this branch in one interleaved run: wall 128.9 -> 79.3 s (-38%), CPU 695 -> 425 s (-39%), code identical for all 7,969 functions (O0 45 -> 24 s, O2-noinline 43 -> 28 s, O2 41 -> 27 s).

How they were found

  • Callee previews were ~40% of decompile CPU (aggregate profile of the eight slowest subset binaries); each is a raw-HIR build plus a full normalize.
    • 14-59% of stable-prefix previews decoded to the same p-code as the complete one. The preview depends on the p-code alone; the evidence kind only labels diagnostics.
    • 11-16% of summary misses were a key another worker was already computing. Non-rayon threads now wait on a per-key OnceLock; rayon workers compute themselves, avoiding the OnceLock/rayon deadlock seen before.
  • Per-pass elapsed_ms from the debug log put callsite_type_prop (39%) and use_driven_type_infer (27%) on top of normalize. Inside the first, drop_unused_call_receivers folds liveness at every nesting level even when no receiver can be dropped.
  • Instrumenting the type fixed point: in 24,270 of 27,033 rounds (90%) the passes undid one another and the round ended exactly where it began, while each pass still reported a change, so nearly every fixed point ran to its 6-round cap. The passes read only the function (PreHirFunction: Eq), so such a round would repeat identically; the loop now stops there.

Later commits

  • fuse_single_predecessor_boundaries deep-copied the run up to the next label for every statement; it now decides first and moves the run. A 4,000-case generated test holds it to the old implementation.
  • The seeded-options cache is keyed by a Weak to the binary's copy-on-write inner data (LoadedBinary::inner_snapshot): while the Weak lives the allocation can be neither freed nor mutated in place, so pointer identity means same contents. Tests cover shared and in-place mutation and fail with the check off.
  • Guard crossings: guards of one block form a contiguous run per value (strictly dominated blocks from the idom chains, binary search for the run). value_crosses_guard stays as the debug-assertion oracle; it held on 3,075 real functions and fires when the new code is broken two different ways.
  • The BFS and candidate-key changes carry the same kind of debug assertion against what they replace.

Tried and dropped

An op read/write index for collect_output_use_sites_outside_block (2.6% self time) measured -0.8%, inside run-to-run noise once the per-builder index build is paid; not kept.

Not done here

Which pass pair undoes the other inside a type round is a convergence defect of its own; fixing it changes output and needs a GED measurement.

Tests

No behaviour change; fission-midend-normalize + fission-pcode green under the test profile and --release, fission-decompiler green, CI clippy line clean, fmt clean.

🤖 Generated with Claude Code

sjkim1127 and others added 4 commits November 14, 2026 16:48
… the whole body

The direct-callee prototype is inferred twice: from the complete decode,
then from a decode capped at the stable-prefix instruction limit, whose
pointer evidence fills slots the complete preview left empty. A callee
shorter than that limit decodes to the same p-code both times, and the
preview is a function of the p-code alone -- the evidence kind only labels
diagnostics -- so the second run reproduces the first and the merge keeps
nothing from it. Each run is a raw-HIR build plus a full normalize.

On the full DecBench dataset 14-59% of prefix previews were such repeats
(ssh-sk-helper 83/486, ssh 167/1163, cf2 667/1135). Profiling the eight
slowest subset binaries put callee previews at ~40% of decompile CPU.

Subset (81 binaries, 7,969 functions), on top of #883: wall 133.8 ->
127.5 s (-4.7%), CPU 721 -> 675 s; code identical for all 7,969 functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e same time

Decompile workers start together and share popular callees, and the
summary cache is filled only after the computation, so workers that miss
the same key concurrently each ran it: 16% of ssh-sk-helper's and 11% of
ssh's summary misses on the full DecBench dataset were a key another worker
was already computing. Misses now go through a per-key OnceLock: the first
worker computes, the others wait for its result, and the result enters the
LRU before it leaves the in-flight map.

Only threads outside the rayon pool wait. A rayon worker blocked on the
cell could be the one the computing thread's own rayon work needs (the
OnceLock-blocks-on-rayon deadlock seen before), so a rayon worker computes
the summary itself as it did before. Previews do not recurse into other
callees, so a computation never waits on its own key.

Subset (81 binaries, 7,969 functions): wall 125.7 -> 123.0 s, CPU 669 ->
626 s (-6.4%); code identical for all 7,969 functions; no hang.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…alifies

drop_unused_call_receivers folds liveness bottom-up at every nesting level
(LivenessTransfer per statement, plus a live-out per nested list), and it
runs inside the type fixed point of every function and every callee
preview -- 6% of decompile samples on the slowest subset binaries. It only
ever rewrites an unprotected receiver of a known API call outside loops,
so when the body has no such assignment its result is already 0. Check
that first.

Subset (81 binaries, 7,969 functions): wall 123.1 -> 116.6 s, CPU 629 ->
614 s; code identical for all 7,969 functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ere it began

The type fixed point runs type_inference, callsite_type_prop,
use_driven_type_infer and type_constraint_prop per round and stops when
none reports a change, capped at six rounds. The passes undo one another
inside a round -- one widens a binding, a later one narrows it back -- so
each reports a change while the round ends exactly where it started. On two
full-dataset binaries 24,270 of 27,033 rounds (90%) did, and almost every
fixed point ran to its cap.

The passes read nothing but the function, so a round that returns to its
starting state would repeat itself identically until the cap and leave the
same state. Compare the function before and after the round (it derives Eq)
and stop when they match.

Subset (81 binaries, 7,969 functions): wall 115.5 -> 97.1 s (-16%), CPU
613 -> 507 s; code identical for all 7,969 functions.

Which pass pair undoes the other is left open; it is a convergence defect
in its own right, but fixing it changes output and needs measuring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 14, 2026 08:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

tabulate_over evaluated the guard once per row, and at every atom leaf
looked the atom up in the atom list by structural PreHirExpr equality --
up to 4,096 rows times every leaf, each a deep comparison. Resolve each
atom to its column once, then evaluate 64 rows per u64 with AND/OR/NOT
over fixed column masks (in-word patterns for atoms 0-5, whole words
selected by the word index above that). Same table, bit for bit.

The row-at-a-time evaluator stays in the tests as an oracle; a generated
set of 400 formulas over 1-12 atoms must agree with it on every row, and
the test fails if either the in-word or the cross-word column pattern is
broken.

Subset (81 binaries, 7,969 functions): wall 93.8 -> 92.6 s, CPU 498 ->
483 s; code identical for all 7,969 functions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sjkim1127 sjkim1127 changed the title perf: callee previews, dead-receiver walk, type fixed point (-27% on the full dataset) perf: callee previews, dead-receiver walk, type fixed point, truth tables (-31% on the full dataset) Nov 14, 2026
sjkim1127 and others added 3 commits November 14, 2026 19:05
Found by attributing library self time (memmove, malloc, hashing) to the
nearest Fission frame in a profile of the eight slowest subset binaries.

- fuse_single_predecessor_boundaries deep-copied the run up to the next
  label for every statement of a list, then looked at the statement. Only
  an `if` with a lone `goto` arm whose target is that next label can be
  rewritten; decide that first and move the run instead of copying it.
  A 4,000-case generated test holds the rewrite to the implementation it
  replaced (kept as the test's oracle) and fails if the two disagree.
- best_prior_definition_for_missing_pred ran a forward BFS per candidate
  block to the same predecessor. One backward BFS over the reversed
  successor edges gives every candidate's distance.
- lookup_candidate_def_keys walked every defined key per lookup. The
  definition table and the register model do not change after the builder
  is created, so the answer is kept per key.

The last two carry debug assertions against the computation they replace;
a release build with debug assertions ran 3,048 functions of five
full-dataset binaries without one firing.

Subset (81 binaries, 7,969 functions): wall 97.7 -> 89.4 s, CPU 480 ->
451 s (-6.0%); code identical for all 7,969 functions.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ved register maps

Binary-level data was rebuilt for every function render and every callee
preview.

- seed_nir_render_options builds `global_names` from the binary's symbol,
  import, function and string tables -- thousands of entries, each a
  sanitized copy. The seeded options are now kept per inner-data snapshot
  and copied out. The key is a `Weak` to the binary's copy-on-write inner
  data (`LoadedBinary::inner_snapshot`): while it exists the allocation can
  be neither freed nor mutated in place, so pointer identity means "same
  contents". Options seeding reads nothing outside the inner data except
  `SelectionAxis::from_env`, which is still read per call. Tests cover an
  unchanged binary, a change made while another handle shares the data,
  and one made in place; the last two fail with the snapshot check off.
- RegisterNamer::from_options copied the options' register map and grouped
  it by offset on each of the several namer builds per function. The two
  derived maps are reused by content of the source map; a test checks that
  a different map gets its own, and fails if only the size is compared.

Subset (81 binaries, 7,969 functions): CPU 450.9 -> 442.6 s (-1.8%), wall
85.0 -> 84.7 s; code identical for all 7,969 functions.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
build_out_of_ssa_facts asked value_crosses_guard for every (member, guard)
pair, and each call walked the dominator chain from the guard's block: the
largest single self-time entry of a decompile, and one that three earlier
attempts (hoisting the guard list, bitmap reachability) did not move,
because they kept the per-pair loop.

Guards of one block share everything but their position, so for a value
and a block the crossed guards are a contiguous run of that block's
guards: the definition reaches every guard of a block it strictly
dominates and the guards after it in its own block; a use lies after all
of a block's guards when its block is reachable from the guard block, and
otherwise after the guards preceding the last use inside the block. The
guard blocks a block strictly dominates are collected once from the idom
chains, each run is found by binary search, and the per-variable result is
read off a reused mark array in guard order.

value_crosses_guard stays as the debug assertion's oracle. It held on
3,075 functions of six full-dataset binaries in a release build with debug
assertions, and fires in the unit tests when the same-block bound is off
by one or only the immediate dominator is recorded.

Subset (81 binaries, 7,969 functions): wall 85.0 -> 80.7 s, CPU 448 ->
431 s (-3.9%); code identical for all 7,969 functions.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@sjkim1127 sjkim1127 changed the title perf: callee previews, dead-receiver walk, type fixed point, truth tables (-31% on the full dataset) perf: callee previews, type fixed point, guard crossings and per-query scans (-38% on the full dataset) Nov 14, 2026

This branch has not been deployed

No deployments
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.

2 participants