Here is an example.
julia> using Colors, BenchmarkTools
julia> rgb_f64 = rand(RGB{Float64}, 1000);
julia> @btime convert.(XYZ{Float64}, $rgb_f64);
130.900 μs (5760 allocations: 113.48 KiB)
julia> precompile(Tuple{typeof(convert), Type{XYZ{Float64}}, RGB{Float64}}) # for example
true
julia> @btime convert.(XYZ{Float64}, $rgb_f64);
130.900 μs (5760 allocations: 113.48 KiB)
julia> @noinline Colors.pow12_5(x::Float64) = x^2 * exp(0.4 * log(x)) # force invalidation (the body is not changed)
julia> @btime convert.(XYZ{Float64}, $rgb_f64);
50.700 μs (2 allocations: 23.52 KiB)
julia> versioninfo()
Julia Version 1.7.0-DEV.1133
Commit db8d09609c (2021-05-21 13:48 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
For the root causes, the following would be appropriate places for discussion, not here.
https://github.com/JuliaLang/julia/issues/35972
https://github.com/JuliaLang/julia/issues/34055