Skip to content

Precompile displaying arrays, and link kernels without a closure - #599

Open
maleadt wants to merge 2 commits into
mainfrom
tb/latency
Open

maleadt wants to merge 2 commits into
mainfrom
tb/latency

Conversation

@maleadt

@maleadt maleadt commented Oct 28, 2026

Copy link
Copy Markdown
Member

Two first-use latency fixes, found while working on the same in Metal.jl.

Displaying a CLArray for the first time compiled for about 400 ms, and on the REPL's TTYTerminal for about 950 ms, while the first garbage collection that frees an array compiled free for 30 ms. The workload doesn't use a device, so these are now precompiled explicitly, displaying arrays in USM (the preferred memory back-end where it is supported). With PoCL and Julia 1.13, the first display of a CLVector takes 34 instead of 419 ms on an IOBuffer and 46 instead of 969 ms on a TTYTerminal. The image grows from 9.6 to 13.1 MB, without a measurable change in load time.

clfunction passed a closure to GPUCompiler.cached_lookup to link a kernel on a cache miss. Its type includes the kernel's function and argument types, so every new kernel compiled it again; a callable struct holding these as values is compiled once, saving about 7 ms of host compilation per new kernel.

`clfunction` passed a closure to `GPUCompiler.cached_lookup` to link the
kernel on a cache miss. The closure's type includes the kernel's function
and argument types, so every new kernel compiled it again, together with
the `methodinstance` call inlined into it.

Use a callable struct holding these types as values instead, which is
compiled once. This saves about 7 ms of host compilation for every new
kernel (PoCL, Julia 1.13).
The first `show` of a `CLArray` compiled for about 400 ms, and on the
REPL's `TTYTerminal` for about 950 ms, while the first garbage collection
that frees an array compiled `free` for 30 ms. The workload doesn't use a
device, so it can't do either; precompile them explicitly, displaying
arrays in USM, the preferred memory back-end where it is supported.

With PoCL and Julia 1.13, the first display of a `CLVector` takes 34 ms
instead of 419 ms on an `IOBuffer`, and 46 ms instead of 969 ms on a
`TTYTerminal`. The image grows from 9.6 to 13.1 MB, without a
measurable change in load time.
@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.75%. Comparing base (4828021) to head (a65c54b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #599      +/-   ##
==========================================
+ Coverage   90.71%   90.75%   +0.04%     
==========================================
  Files          18       18              
  Lines        1799     1807       +8     
==========================================
+ Hits         1632     1640       +8     
  Misses        167      167              

☔ 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.

This branch has not been deployed

No deployments
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