Skip to content

Commit

Permalink
only infer concrete union-split signatures to cut down on inference
Browse files Browse the repository at this point in the history
reduce O(n^2) behavior of `jl_recache_types`

these help #24383
  • Loading branch information
JeffBezanson committed Oct 29, 2017
1 parent 5478834 commit 2b4cb95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ function _methods_by_ftype(t::ANY, lim::Int, world::UInt, min::Array{UInt,1}, ma
end
end
if 1 < nu <= 64
return _methods_by_ftype(Any[tp...], t, length(tp), lim, [], world, min, max)
ms = _methods_by_ftype(Any[tp...], t, length(tp), lim, [], world, min, max)
if all(m->isleaftype(m[1]), ms)
return ms
end
end
# XXX: the following can return incorrect answers that the above branch would have corrected
return ccall(:jl_matching_methods, Any, (Any, Cint, Cint, UInt, Ptr{UInt}, Ptr{UInt}), t, lim, 0, world, min, max)
Expand Down
5 changes: 3 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,8 @@ static jl_datatype_t *jl_recache_type(jl_datatype_t *dt, size_t start, jl_value_
t = dt;
}
assert(t->uid != 0);
if (t == dt && v == NULL)
return t;
// delete / replace any other usages of this type in the backref list
// with the newly constructed object
size_t i = start;
Expand Down Expand Up @@ -3087,8 +3089,7 @@ static void jl_recache_types(void)
if (jl_is_datatype(o)) {
dt = (jl_datatype_t*)o;
v = dt->instance;
assert(dt->uid == -1);
t = jl_recache_type(dt, i + 2, NULL);
t = dt->uid == -1 ? jl_recache_type(dt, i + 2, NULL) : dt;
}
else {
dt = (jl_datatype_t*)jl_typeof(o);
Expand Down

0 comments on commit 2b4cb95

Please sign in to comment.