-
-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange @allocated numbers for function calls to interpolation objects #2844
Comments
I think the first cell is being optimized more heavily than the second, and Julia is able to optimize away the actual This reminds me of JuliaLang/julia#38880 (comment) In the REPL, if you make sure that the call cannot be optimized away (by storing the result), you get 16 allocs in both cases: julia> using Interpolations
julia> let
t = interpolate((1:10,), rand(10), Gridded(Linear()))
println(@allocated t(5))
end
0
julia> let
t = interpolate((1:10,), rand(10), Gridded(Linear()))
fieldnames(typeof(t))
println(@allocated t(5))
end
0
julia> result = Ref(0.0);
julia> let
t = interpolate((1:10,), rand(10), Gridded(Linear()))
fieldnames(typeof(t))
println(@allocated result[] = t(5))
end
16
julia> let
t = interpolate((1:10,), rand(10), Gridded(Linear()))
println(@allocated result[] = t(5))
end
16
The difference between the REPL and Pluto is in the way Pluto runs code: it will wrap your code in a try catch, a timer function, etc, and sometimes even rewrites your toplevel code into a function body and calls the function instead (#720). So the heuristics were not able to optimize as well in Pluto as in the REPL. |
I'm trying to reduce allocations during function calls to Interpolation objects in Interpolations.jl package. But I get this strange result:
But then I put the same code in a file, they both return zero:
Output is
I'm truly perplexed. Greatly appreciate it if someone can shed some light on this.
Pluto.jl is v0.19.40; and
The text was updated successfully, but these errors were encountered: