Skip to content

bench: add variant-switch.mo (baseline)#6033

Merged
ggreif merged 1 commit intomasterfrom
gabor/variant-switch-bench
Apr 20, 2026
Merged

bench: add variant-switch.mo (baseline)#6033
ggreif merged 1 commit intomasterfrom
gabor/variant-switch-bench

Conversation

@ggreif
Copy link
Copy Markdown
Contributor

@ggreif ggreif commented Apr 19, 2026

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 on master) for the dispatch-optimisation work on #5927 (masked br_table) and any follow-ups.

Actor methods:

  • go — top-level size tree + size fibCore, ×10k.
  • evalBenchfib(7) via direct AST eval, compiled finally-tagless form, and the AST→FT transform itself; ×100 each.
  • weekdayBenchisWeekend (7 explicit arms) vs isWeekendOr (same dispatch via or-patterns); ×10k over a 7-arm Weekday variant.
  • getPerfData — reports rts_lifetime_instructions.

Master baseline

Metric Instructions
size tree + fibCore (×10k) 137,590,321
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

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.only passes on master.
  • drun output captured in test/bench/ok/variant-switch.drun-run.ok.

🤖 Generated with Claude Code

…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>
@ggreif ggreif requested a review from a team as a code owner April 19, 2026 22:57
@ggreif ggreif changed the title bench: add variant-switch benchmark (baseline) bench: add variant-switch.mo benchmark (baseline) Apr 19, 2026
@ggreif ggreif enabled auto-merge April 19, 2026 23:03
@ggreif ggreif changed the title bench: add variant-switch.mo benchmark (baseline) bench: add variant-switch.mo (baseline) Apr 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Comparing from cff143d to 51eb1b0:
The produced WebAssembly code seems to be completely unchanged.
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

@ggreif ggreif self-assigned this Apr 19, 2026
Copy link
Copy Markdown
Contributor

@alexandru-uta alexandru-uta left a comment

Choose a reason for hiding this comment

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

thanks, nice benchmark.

@ggreif ggreif added this pull request to the merge queue Apr 20, 2026
Merged via the queue into master with commit c42a9b9 Apr 20, 2026
20 checks passed
@ggreif ggreif deleted the gabor/variant-switch-bench branch April 20, 2026 06:48
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