From 17d34b2c79b6d9bc0e4f83e88214762c961caace Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 15 Oct 2026 18:42:16 +0200 Subject: [PATCH] Hash compiler configuration kwargs without boxing them compiler_config runs on every zefunction call, so on every launch of a KernelAbstractions kernel, which passes name, always_inline and sub_group_size. Hashing them as a Base.Pairs boxes each value. Hash the NamedTuple instead, which is fully typed and whose hash includes the field names, so distinct settings still get distinct configurations. With the kwargs of a KernelInterface launch, compiler_config goes from 237 ns and 4 allocations to 85 ns and none (Iris Xe, Julia 1.12). --- src/compiler/compilation.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl index f8aa0cb0..6b5e3a5c 100644 --- a/src/compiler/compilation.jl +++ b/src/compiler/compilation.jl @@ -253,7 +253,8 @@ const _toolchain = Ref{Any}() const _compiler_configs = Dict{UInt, oneAPICompilerConfig}() const compiler_config_lock = ReentrantLock() function compiler_config(dev; kwargs...) - h = hash(dev.driver, hash(dev, hash(kwargs))) + # (as a `NamedTuple`: hashing the `Pairs` boxes each value, on every launch) + h = hash(dev.driver, hash(dev, hash(values(kwargs)))) Base.@lock compiler_config_lock begin get!(_compiler_configs, h) do _compiler_config(dev; kwargs...)