Function compiles every time

If the expressions have exactly the same hash this should already work.

Demo:

julia> using RuntimeGeneratedFunctions

julia> ex = :(x -> x^2 - 1)
:(x->begin
          #= REPL[2]:1 =#
          x ^ 2 - 1
      end)

julia> RuntimeGeneratedFunctions.init(Main)

julia> f = @RuntimeGeneratedFunction(ex)
RuntimeGeneratedFunction(#=in Main=#, #=using Main=#, :((x,)->begin
          #= REPL[2]:1 =#
          x ^ 2 - 1
      end))

julia> @time f(1.0)
  0.051278 seconds (64.49 k allocations: 4.051 MiB, 99.96% compilation time)
0.0

julia> @time f(1.0)
  0.000004 seconds (1 allocation: 16 bytes)
0.0

julia> g = @RuntimeGeneratedFunction(ex)
RuntimeGeneratedFunction(#=in Main=#, #=using Main=#, :((x,)->begin
          #= REPL[2]:1 =#
          x ^ 2 - 1
      end))

julia> @time g(1.0)
  0.000008 seconds (1 allocation: 16 bytes)
0.0

julia> typeof(f) === typeof(g)
true

Maybe the hashes aren’t exactly equal here for some reason?

1 Like