You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: quadratic branch lookup in prove for large switches #82407
Compiled a generated switch whose cases make distinct calls to a
non-inlined function:
python3 - <<'PY' > switch.gon = 4000print('package p')print('//go:noinline')print('func F(x int) int { return x }')print('func Lookup(x int) int { switch x {')for i in range(n): print(f'case {i}: return F({i * 3 + 1})')print('}; return -1 }')PY
go tool compile -d=ssa/prove/time switch.go
Repeated with 1,000, 2,000, 4,000 and 8,000 cases.
What did you see happen?
Median prove-pass times over five runs on an Intel i9-13900K:
Cases
Prove time
1,000
0.88 ms
2,000
3.24 ms
4,000
12.40 ms
8,000
69.13 ms
The jump-table case in getBranch
scans the successors for each case visited by prove. An 8,000-case CPU
profile attributes 60 ms of 360 ms sampled compiler CPU time to this
scan through SparseTree.IsAncestorEq.
CL 841945 changes traversal order in the same pass, but leaves this scan
unchanged.
What did you expect to see?
Branch lookup should not scan the whole jump table for each direct
successor. This produces quadratic work as the number of cases grows.
Activity
gabyhelp commentedon Oct 22, 2026
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
gopherbot commentedon Oct 22, 2026
Change https://go.dev/cl/852526 mentions this issue:
cmd/compile: avoid scanning direct jump-table branches