-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Method definition can take quadratic time #45424
Comments
does this have significant TTFP implications? |
Probably not, this extreme pattern won't be seen that often. |
see #45395 |
Are you saying that issue is related to this in some way? |
I do not know, but it is (another?) quadratic or exponential thing happening while compiling a method |
Now we merged #45276 and it seems to be the lowering time is a dominant factor of the whole compilation for this kind of case: julia> function time_definition(n)
ex = Expr(:block)
var = gensym()
push!(ex.args, :($var = x))
for _ = 1:n
newvar = gensym()
push!(ex.args, :($newvar = $var + 1))
var = newvar
end
@time @eval global function quadratic(x)
$ex
end
end
time_definition (generic function with 1 method)
julia> function time_execution()
s = time_ns()
@eval quadratic(42)
e = time_ns()
Base.time_print(e - s)
end
time_execution (generic function with 1 method)
julia> time_definition(1000)
0.044844 seconds (11.15 k allocations: 628.467 KiB)
quadratic (generic function with 1 method)
julia> time_execution()
0.027912 seconds
julia> time_definition(10000)
1.738030 seconds (118.12 k allocations: 6.034 MiB)
quadratic (generic function with 1 method)
julia> time_execution()
0.400399 seconds
julia> time_definition(20000)
6.889014 seconds (238.12 k allocations: 12.108 MiB, 0.23% gc time)
quadratic (generic function with 1 method)
julia> time_execution()
1.125169 seconds |
This seems to have been fixed on v1.10. |
MRE:
It's nice to have this improved as we are going to fix the quadratic behavior of inference soonish (#45276 )
The text was updated successfully, but these errors were encountered: