Skip to content

perf: Group match rows by head constructor when specializing [match-stress -41%] - #87

Draft
xmakro wants to merge 1 commit into
perf/base-0713from
perf/match-head-ctor-index
Draft

perf: Group match rows by head constructor when specializing [match-stress -41%]#87
xmakro wants to merge 1 commit into
perf/base-0713from
perf/match-head-ctor-index

Conversation

@xmakro

@xmakro xmakro commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Exhaustiveness checking specializes the pattern matrix with each constructor of a column in
turn, and each specialization walks every row of the matrix. A match with one arm per variant of
an enum with V variants therefore does V passes over V rows. On match-stress, which is mostly
PartialEq derives on large enums, compute_exhaustiveness_and_usefulness is 42% of the
instructions of the whole compile.

Group the rows of a column by the discriminant of their head constructor once, so that
specializing with a constructor only looks at the rows whose head has the same discriminant plus
the rows whose head decides coverage by something other than equality (wildcards, ranges, slices,
opaque constants). Both lists are kept in row order and merged, so rows are still visited in
their original order, and is_covered_by still decides. The index is only built when a column
has more than one constructor and the matrix has at least 8 rows.

Measured on 12 crates, Check and Debug, instructions:u, isolated against the same base:

match-stress               check   -41.43%
match-stress               debug   -40.39%

The other 22 cells (bitmaps, clap_derive, cranelift-codegen, hyper, image, many-assoc-items,
nalgebra, ripgrep, serde, syn, typenum) are all within 0.14%, geomean -4.30%.

The full tests/ui suite passes (21309 tests), as do tests/incremental (178 tests) and the
rustc_pattern_analysis unit tests.

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.

1 participant