Skip to content

Don't allocate when building signature types on Julia 1.14 - #1025

Merged
maleadt merged 1 commit into
mainfrom
tb/sigtt-alloc
Oct 17, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/sigtt-alloc

Conversation

@maleadt

@maleadt maleadt commented Oct 17, 2026

Copy link
Copy Markdown
Member

On Julia 1.14, signature_type_by_tt maps dispatch_key over the parameters of the tuple type. That builds a Vector, so even for a constant tuple type the signature isn't folded and methodinstance allocates on every launch of a cached kernel, proportionally to the number of arguments. This breaks KernelAbstractions' POCL "launch with many arguments" test on nightly.

This PR splats the parameters as-is when neither the callee nor any argument is a Type{...}, the only case where dispatch_key changes anything. Otherwise it splats a generator, which folds just like plain splatting does.

Using the generator in both cases would also fix the allocations, but for a tuple type that's only known at run time it's 2-3x slower than map. The split version is faster than map there too:

methodinstance on 1.14.0-DEV before after
constant tt, 5 params 180 ns, 128 B ~10-20 ns, 0 B
constant tt, 41 params 432 B 0 B
constant tt with a Type{Int} argument 240 B 0 B
runtime tt, 5 params 179 ns, 128 B 159 ns, 32 B
runtime tt, 41 params 856 ns, 432 B 732 ns, 32 B

With the KA reproducer on nightly, a POCL launch now allocates 96 B both with 40 arguments (528 B before) and with 4 (240 B before).

The new test fails on nightly without the fix (432 B and 240 B) and passes on 1.11 through 1.14, also with --code-coverage=user --check-bounds=yes. It's skipped on 1.10, where methodinstance is the generic lookup.

Fixes #1024

On Julia 1.14, signature_type_by_tt maps dispatch_key over the parameters
of the tuple type. That builds a Vector, which keeps the signature from
being folded to a constant, so every methodinstance call (i.e., every
launch of a cached kernel) allocated proportionally to the number of
arguments, regressing KernelAbstractions' POCL launch-allocation test.

Splat the parameters directly when none of them is a Type{...}, which is
also what's cheapest for a non-constant tuple type, and use a generator
otherwise, which folds just like splatting does.

Fixes #1024
@maleadt

maleadt commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

CI failure unrelated, JuliaGPU/CUDA.jl#3408.

@maleadt
maleadt merged commit 4003c66 into main Oct 17, 2026
35 of 36 checks passed
@maleadt
maleadt deleted the tb/sigtt-alloc branch October 17, 2026 15:14
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.

signature_type_by_tt allocates on every launch on Julia 1.14

1 participant