Skip to content

Give the default method table view one type for every stack depth - #1080

Merged
maleadt merged 1 commit into
mainfrom
tb/method-table-stack
Nov 6, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/method-table-stack

Conversation

@maleadt

@maleadt maleadt commented Nov 5, 2026

Copy link
Copy Markdown
Member

The default method_table_view nests a StackedMethodTable per method table, and GPUInterpreter is parametric in the view, so back-ends that stack a different number of tables get different interpreter types. The inference code specialized on that type is only shared between packages whose stacks happen to have the same depth. GPUCompiler's own precompilation workload (native target, one table) covers none of the back-ends.

This showed up as a Metal.jl precompilation regression (32 → 38.7 s on CI, JuliaGPU/Metal.jl#1129). Metal stacks three tables plus SHARED_METHOD_TABLE. Until KernelAbstractions 0.10.5, so did KA's POCL back-end, whose precompilation workload launches a kernel, so Metal reused the inference code in KA's package image. JuliaGPU/KernelAbstractions.jl#944 added a fourth table to POCL, and Metal had to compile it all again.

This PR replaces the nested chain with a flat MethodTableStack that holds the tables in a vector. It has the same lookup semantics, so every back-end that returns its tables from method_tables (and the native target) shares one interpreter type, and with it the inference code GPUCompiler precompiles.

Measured on an M1, Julia 1.13, user CPU time of Base.compilecache (2 interleaved rounds):

2.21 this PR
Metal.jl, with KA 0.10.5 69.4 / 67.6 s 54.2 / 53.3 s
Metal.jl, with KA's workload disabled 75.6 / 73.0 s 58.0 / 59.7 s
GPUCompiler 36.8 / 37.2 s 36.9 / 37.1 s

Compiling 29 new Metal kernels in a warm session takes the same time (1.23–1.32 s), so lookups through the flat stack don't slow down inference.

This doesn't change the back-end interface. StackedMethodTable is still available, and back-ends that override method_table_view keep working, but they get their own interpreter type and don't share the precompiled code. OpenCL.jl does that today and could switch to method_tables, though that would also add SHARED_METHOD_TABLE to its stack.

The default `method_table_view` nested a `StackedMethodTable` per method table, and
`GPUInterpreter` is parametric in the view, so back-ends stacking a different number of tables
got different interpreter types. The inference code specialized on that type is only shared
between packages whose stacks happen to have the same depth: GPUCompiler's own precompilation
covers none of the back-ends, and Metal.jl precompiled ~15 s of CPU time faster only because
KernelAbstractions' POCL back-end happened to stack as many tables, until KernelAbstractions
0.10.5 added one.

Look up the tables in a flat `MethodTableStack` instead, with the same semantics as the
nested chain, so every back-end that returns its tables from `method_tables` shares one
interpreter type, and the inference code that GPUCompiler precompiles.
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.95652% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.81%. Comparing base (7660c58) to head (6eb6bac).

Files with missing lines Patch % Lines
src/jlgen.jl 86.95% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1080      +/-   ##
==========================================
- Coverage   92.84%   92.81%   -0.04%     
==========================================
  Files          31       31              
  Lines        7732     7775      +43     
==========================================
+ Hits         7179     7216      +37     
- Misses        553      559       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 45e224f into main Nov 6, 2026
36 checks passed
@maleadt
maleadt deleted the tb/method-table-stack branch November 6, 2026 12:45
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