Accessors.jl icon indicating copy to clipboard operation
Accessors.jl copied to clipboard

Precompile some functions which back up macros

Open Tortar opened this issue 1 year ago • 1 comments

I wonder if we could precompile some functions to reduce first time latency calls, e.g. I think we can go from f timings to g timings in this example scenario:

julia> struct A
           x::Int
       end

julia> struct B
           y::Float64
       end

julia> using Accessors

julia> f(s) = @set s.x = 3
f (generic function with 1 method)

julia> g(s) = @set s.y = 3.0
g (generic function with 1 method)

julia> s = A(1)
A(1)

julia> @time @eval f(s)
  0.160497 seconds (98.85 k allocations: 7.246 MiB, 99.89% compilation time)
A(3)

julia> s = B(1.0)
B(1.0)

julia> @time @eval g(s)
  0.013224 seconds (39.48 k allocations: 2.671 MiB, 98.70% compilation time)
B(3.0)

which is more than 10 times better

Tortar avatar Sep 22 '24 10:09 Tortar

I'm not too familiar with optimal precompilation setups, but personally won't be against a PR that provides measurable improvements to TTFX. Please, just ensure that precompile times don't become unreasonably long :)

aplavin avatar Sep 22 '24 17:09 aplavin