Repository navigation
Remove the hashing fast paths from pattern matching - #8900
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## char-int-ranges #8900 +/- ##
===================================================
- Coverage 81.04% 81.03% -0.02%
===================================================
Files 455 455
Lines 63675 63630 -45
===================================================
- Hits 51605 51561 -44
+ Misses 12070 12069 -1
🚀 New features to boost your workflow:
|
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
#8868 made exhaustiveness checking and match compilation find constants by hashing, because an expanded char range turned one pattern into thousands of distinct constants. Char ranges are now one pattern each, so the hash tables in `Parmatch.filter_all`, `Parmatch.get_mins_pats` and `Matching.divide`, and the `const_key` that kept their keys consistent with char/int equality, are removed. A dead `char` check in comparison specialization goes too: `char` expands to `int` before it. Review: How much slower do large switches compile? A switch with 1,000 int or string cases compiles 0.02-0.03 s slower; one with 10,000 int cases takes 6.3 s instead of 3.2 s. Polymorphic variants are unaffected: 10,000 cases take about 35 s either way, as other quadratic steps dominate. Review: Does the output change? No. All committed snapshots are byte-identical, and so is the JS of 1,500 fuzzer programs and the benchmark switches. Area: typechecker lambda Output: unchanged Formatting: unchanged Formats: none PPX: unchanged Editor: unchanged Tests: none, because the output is unchanged and existing tests cover the behaviour Measured: best of 3 bsc wall time, with -> without the fast paths: 1,000 int cases 0.07 -> 0.09 s; 3,000 int 0.34 -> 0.63 s; 10,000 int 3.23 -> 6.27 s; 1,000 string 0.04 -> 0.07 s; 3,000 string 0.17 -> 0.52 s; 10,000 string 1.55 -> 5.38 s; 1,000 polymorphic variant 0.23 -> 0.25 s; 10,000 polymorphic variant 35.47 -> 36.45 s Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo Signed-off-by: Christoph Knittel <ck@cca.io>
d6c5849 to
c8313d5
Compare
Follow-up to the #7028 stack, on top of #8894.
#8868 added hashing fast paths to exhaustiveness checking and match compilation, because an expanded char range turned one pattern into thousands of distinct constants. Since #8893, a char range is one pattern, so this PR removes them:
Parmatch.filter_allParmatch.get_mins_pats, replaced byget_mins le_patsagainhash_keyoption ofMatching.divideParmatch.const_key, which kept the hash keys consistent with char/int equalityIt also removes a dead
charcheck in comparison specialization (translcore.ml):charexpands tointbefore that check.Cost (best of 3
bscwall times; switches with N cases plus_):The fast paths only matter beyond a few thousand cases. Even with them, very large switches stay slow because of other quadratic steps; polymorphic variants don't benefit at all.
Output: unchanged. The committed snapshots are byte-identical, as is the JS of the benchmark switches and of 1,500 fuzzer programs over char, int and mixed ranges.
🤖 Generated with Claude Code
https://claude.ai/code/session_01JALXUyHhkDqzcB3WuW9Svo