Skip to content

Precompile displaying N0f8 and N0f16 - #352

Open
PatrickHaecker wants to merge 2 commits into
JuliaMath:masterfrom
PatrickHaecker:precompile-display
Open

PatrickHaecker wants to merge 2 commits into
JuliaMath:masterfrom
PatrickHaecker:precompile-display

Conversation

@PatrickHaecker

@PatrickHaecker PatrickHaecker commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Showing a value or a vector for the first time was slow. Precompiling show and print for the terminal and for buffers cuts the first display in the terminal from 302 to 82 ms on Julia 1.10 and from 913 to 88 ms on Julia 1.13, and the first repr from 438 to 113 ms and from 553 to 107 ms. Loading becomes 8 ms (1.10) and 2 ms (1.13) slower, and the package image grows by about 1 MiB. Invalidations do not change, neither from loading the package nor from loading ColorTypes and Colors afterwards.

@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.25%. Comparing base (6decae1) to head (9b952ff).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #352      +/-   ##
==========================================
+ Coverage   97.22%   97.25%   +0.02%     
==========================================
  Files           7        7              
  Lines         792      800       +8     
==========================================
+ Hits          770      778       +8     
  Misses         22       22              

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

@kimikage

Copy link
Copy Markdown
Collaborator

Personally, I believe this is worthwhile.
However, opinions vary regarding the trade-offs involved in TTFX.
If there are no objections after some time has passed, I'll merge this PR.

@kimikage

Copy link
Copy Markdown
Collaborator

BTW, I am considering registering the TTFX benchmark snippet for Colors.jl.
JuliaGraphics/Colors.jl#590

Displaying RGB{N0f8} should be in the snippet.

Patrick Häcker added 2 commits October 16, 2026 09:09
Showing a value or a vector for the first time was the slowest first use
of the package. Precompiling `show` and `print` for the terminal and for
buffers cuts the first display in the terminal from 302 to 82 ms on
Julia 1.10 and from 913 to 88 ms on Julia 1.13, and the first `repr`
from 438 to 113 ms and from 553 to 107 ms. Loading becomes 8 ms (1.10)
and 2 ms (1.13) slower, and the package image grows by about 1 MiB.
Invalidations do not change, neither from loading the package nor from
loading ColorTypes and Colors afterwards.
Scripts whose output is piped, such as CI jobs and TTFX benchmarks, print
through `IOContext{Base.PipeEndpoint}`. Without these directives, the first
display of an `RGB{N0f8}` vector takes about 2 s on Julia 1.13 and 1.4 s on
1.10, with them about 0.4 s.
@PatrickHaecker

Copy link
Copy Markdown
Collaborator Author

BTW, I am considering registering the TTFX benchmark snippet for Colors.jl. JuliaGraphics/Colors.jl#590

Displaying RGB{N0f8} should be in the snippet.

I am not sure whether I understood what you have asked for here. FixedPointNumbers.jl can't precompile RGB{N0f8}, because Colors.jl depends on FixedPointNumbers.jl, not the other way round. So Colors.jl needs to precompile RGB{N0f8}.

However, I let the agent check whether we can do something to accelerate the use case and indeed we can. Turns out that precompiling Base.PipeEndpoint can also be useful for types like this.


🤖:
I measured your draft from JuliaGraphics/Colors.jl#590, with a REPL-style display of an RGB{N0f8} and a Vector{RGB{N0f8}} added (ColorTypes 0.12.4, Colors 0.13.3, fastest of 5 fresh processes, in ms):

first display of RGB{N0f8} stdout master 7f91b71 (TTY + buffers) 9b952ff (+ pipes)
REPL-style show, Julia 1.13 pipe 2488 1906 428
REPL-style show, Julia 1.10 pipe 1376 1342 414
println(collect(p_max)), Julia 1.13 pipe 852 784 362

julia-ttfx-check runs the workload with stdout going to a pipe, so the first commit alone would not have shown up in such a benchmark. The second commit adds IOContext{Base.PipeEndpoint}, which also covers scripts whose output is piped, as in CI. The package image grows by another 0.6 MiB, and the load time changes by less than the noise. Writing to a file needs no directive, since it is already fast on master.

RGB{N0f8} benefits because the directives for N0f8 and Vector{N0f8} compile the array printing code for these IO types, and RGB{N0f8} display uses the same code.


👨:
I added precompiling Base.PipeEndpoint to the PR.

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.

2 participants