From 7f91b715cc272e6f28ba3a0603b53e994a83db51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=A4cker?= Date: Sat, 10 Oct 2026 08:47:46 +0200 Subject: [PATCH 1/2] Precompile the display of `N0f8` and `N0f16` 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. --- src/precompile.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/precompile.jl b/src/precompile.jl index 83810a7..359217f 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -29,5 +29,12 @@ function _precompile_() precompile(Tuple{typeof(convert),Type{T},S}) precompile(Tuple{typeof(convert),Type{S},T}) end + # display in the terminal and into buffers (e.g. `repr`) + for IOT in (IOContext{Base.TTY}, IOContext{IOBuffer}, IOBuffer) + precompile(Tuple{typeof(show),IOT,T}) + precompile(Tuple{typeof(print),IOT,T}) + precompile(Tuple{typeof(show),IOT,MIME"text/plain",T}) + precompile(Tuple{typeof(show),IOT,MIME"text/plain",Vector{T}}) + end end end From 9b952ff91373926cf845a51080e11e27b1b35050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=A4cker?= Date: Fri, 16 Oct 2026 09:30:05 +0200 Subject: [PATCH 2/2] Precompile the display of `N0f8` and `N0f16` into pipes 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. --- src/precompile.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/precompile.jl b/src/precompile.jl index 359217f..7666104 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -29,8 +29,8 @@ function _precompile_() precompile(Tuple{typeof(convert),Type{T},S}) precompile(Tuple{typeof(convert),Type{S},T}) end - # display in the terminal and into buffers (e.g. `repr`) - for IOT in (IOContext{Base.TTY}, IOContext{IOBuffer}, IOBuffer) + # display in the terminal, into pipes and into buffers (e.g. `repr`) + for IOT in (IOContext{Base.TTY}, IOContext{Base.PipeEndpoint}, IOContext{IOBuffer}, IOBuffer) precompile(Tuple{typeof(show),IOT,T}) precompile(Tuple{typeof(print),IOT,T}) precompile(Tuple{typeof(show),IOT,MIME"text/plain",T})