bionanoimaging / FourierTools.jl

Tools for working with Fourier space.
https://bionanoimaging.github.io/FourierTools.jl/stable/
MIT License
54 stars 6 forks source link

Add precompilation for FourierTools #28

Open roflmaostc opened 1 year ago

roflmaostc commented 1 year ago

Some timings for adding SnoopPrecompile

There is certainly improvement in Time-to-first-X (TTFX) but using FourierTools slowed down :/

# THIS PR

julia> @time @eval begin
        using FourierTools; resample(randn((3,3)), (4,4));
       end
  1.837442 seconds (4.37 M allocations: 330.662 MiB, 5.73% gc time, 37.63% compilation time: 35% of which was recompilation)
4×4 Matrix{Float64}:
  2.50649    0.177745  -1.26525     1.06349
  0.356397  -0.684275  -2.04213    -1.00146
 -1.33411   -0.982222  -0.792645   -1.14453
  0.815986  -0.120202  -0.0157615   0.920427

julia> @time @eval begin
        using FourierTools
       end
  1.233218 seconds (3.56 M allocations: 291.111 MiB, 7.55% gc time, 7.26% compilation time: 36% of which was recompilation)

# master branch

julia> @time begin
        using FourierTools
       end
  0.813568 seconds (2.46 M allocations: 178.026 MiB, 3.53% gc time, 9.22% compilation time: 25% of which was recompilation)

julia> @time @eval begin
        using FourierTools; resample(randn((3,3)), (4,4));
       end
  2.399415 seconds (8.97 M allocations: 544.981 MiB, 12.13% gc time, 69.04% compilation time: 1% of which was recompilation)
4×4 Matrix{Float64}:
 -0.206244   1.54404   2.20982   0.459536
  0.4502     1.25477   1.59361   0.789031
 -0.259531  -1.75128  -0.430379  1.06137
 -0.915975  -1.46202   0.185834  0.731878
roflmaostc commented 1 year ago

Add this copied message from slack for a moment:

Here's what I would do:
First, make a "representative workload" for your package. Something that uses the most common latency-sensitive functions. This is probably what you have inside your SnoopPrecompile block?
Put this workload inside a function, then check it's type stable with JET's report_opt . Make type stable as necessary
Check for type piracy. This can be automated using this script here: https://discourse.julialang.org/t/piracy-hunting/90119. Remove all piracy you find
roflmaostc commented 1 year ago

Julia 1.9:


# without precomp
julia> @time @eval begin
               using FourierTools; resample(randn((3,3)), (4,4));
              end
  2.347064 seconds (7.83 M allocations: 521.891 MiB, 7.21% gc time, 71.20% compilation time)

julia> @time @eval begin
               using FourierTools
              end
  0.667420 seconds (1.51 M allocations: 101.459 MiB, 6.05% gc time, 0.93% compilation time)

# with precompile

julia> @time @eval begin
               using FourierTools
              end

  0.896489 seconds (2.05 M allocations: 141.270 MiB, 6.69% gc time, 0.69% compilation time)

julia> @time @eval begin
               using FourierTools; resample(randn((3,3)), (4,4));
              end
  1.032369 seconds (2.35 M allocations: 160.550 MiB, 6.08% gc time, 13.95% compilation time)
4×4 Matrix{Float64}:
 1.40546     -1.01361   -0.690086  1.72899
 0.0448578   -1.07521   -0.575482  0.544589
 0.00392657  -0.224145   1.05394   1.28201
 1.36453     -0.162546   0.939333  2.46641

``