-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Very long compile time for recursive function of dynamic tuple type #6704
Comments
(this isn't actually a problem for me, as I changed |
julia> function print_values2(dict::MyType, depth::Int,
parent_index::ANY, parent_str::String)
indexset = dict.indexsets[depth]
depth == length(dict.indexsets) && return
for i = 1:length(indexset)
index = indexset[i]
print_values(dict,depth+1,
parent_index == nothing ? (index,) : tuple(parent_index...,index,),
(parent_index == nothing ? "" : parent_str) * "$index,")
end
end
print_values2 (generic function with 1 method)
julia> @time code_typed(print_values2,typeof((mydict, 1, nothing, "")))
elapsed time: 0.000976887 seconds (78104 bytes allocated) Tuple is a special internal type. Since it is changes type on every function call, it appears that julia tries to generate many unique functions for each possible tuple type. There are some limits to that, but they are pretty high. Using |
I figured it might be something like that, but I thought there might be something pathological going on - after all, the function, as called, doesn't even recurse. If you change the fourth argument from |
@vtjnash I think you have a typo: |
oh, that would explain it more. oops |
@JeffBezanson the following patch has no impact on the perf or regular test, but improves the compile time for this from 23 seconds to 0.03 seconds. thoughts? diff --git a/base/inference.jl b/base/inference.jl
index d08f6e0..0675c0d 100644
--- a/base/inference.jl
+++ b/base/inference.jl
@@ -1123,6 +1123,9 @@ function tmerge(typea::ANY, typeb::ANY)
if is(typeb,NF)
return typea
end
+ if typea <: Tuple && typeb <: Tuple && !(typea <: typeb || typeb <: typea)
+ typea = Union(typea,Tuple)
+ end
if typea <: typeb
return typeb
end |
Eh, that's only a 766x speedup :) |
as written, yes. i was trying to take into existing account type unions. in pseudo-code: if hastuples(typea) && hastuples(typeb) && !all_tuples_same(typea, typeb)
typea = Union(Tuple, typea, typeb); typeb = None
end where |
I see. Well, if it doesn't cause any perf regressions let's just put in the |
Here is the code, it has been whittled down extensively from the original version but is still a little unwieldy. On Julia HEAD it reports
The text was updated successfully, but these errors were encountered: