bench: add variant-switch.mo (baseline)#6033
Merged
Conversation
…m dispatch Adds a benchmark that exercises variant-switch dispatch across several shapes, to serve as a baseline for dispatch-optimisation work. Actor methods: - go: top-level size tree + size fibCore, 10k iterations. - evalBench: fib(7) via direct AST eval, a compiled finally-tagless form, and the AST→FT transform itself — 100 iterations each. - weekdayBench: isWeekend vs isWeekendOr over a 7-arm Weekday variant, 10k iterations each — compares explicit-arm vs or-pattern forms. - getPerfData: reports rts_lifetime_instructions. Numbers on master (baseline): - size tree + fibCore (×10k): 137,590,321 instructions - eval fib(7) AST (×100): 24,509,348 - eval fib(7) FT (×100): 21,536,248 - AST→FT transform (×100): 1,189,148 - isWeekend (×10k × 7 arms): 10,010,321 - isWeekendOr (×10k × 7 arms): 11,050,321 This file lands intentionally on master so future dispatch work can show deltas against this reference point. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
variant-switch.mo benchmark (baseline)
variant-switch.mo benchmark (baseline)variant-switch.mo (baseline)
Contributor
alexandru-uta
approved these changes
Apr 20, 2026
Contributor
alexandru-uta
left a comment
There was a problem hiding this comment.
thanks, nice benchmark.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
test/bench/variant-switch.mo— a small GHC-Core-like interpreter that exercises 9-arm variant-switch dispatch in several shapes. Serves as a reference point (baseline onmaster) for the dispatch-optimisation work on #5927 (maskedbr_table) and any follow-ups.Actor methods:
go— top-levelsize tree + size fibCore, ×10k.evalBench—fib(7)via direct AST eval, compiled finally-tagless form, and the AST→FT transform itself; ×100 each.weekdayBench—isWeekend(7 explicit arms) vsisWeekendOr(same dispatch viaor-patterns); ×10k over a 7-armWeekdayvariant.getPerfData— reportsrts_lifetime_instructions.Master baseline
size tree + fibCore(×10k)eval fib(7)AST (×100)eval fib(7)FT (×100)isWeekend(×10k × 7 arms)isWeekendOr(×10k × 7 arms)With #5927 applied, the explicit-arm dispatch numbers drop materially; or-patterns currently don't benefit (separate follow-up).
Test plan
make -C test/bench variant-switch.onlypasses onmaster.test/bench/ok/variant-switch.drun-run.ok.🤖 Generated with Claude Code