Skip to content

Commit

Permalink
typemap: improve quality of leaf split (#48925)
Browse files Browse the repository at this point in the history
Introduce another optional layer of indirection, doing lookup on first
typename always, then leaftypes. This lets the intersection-iterators
skip a lot of jl_isa queries later.
  • Loading branch information
vtjnash authored Mar 8, 2023
1 parent 7ace0fb commit eb4b1a7
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 76 deletions.
32 changes: 17 additions & 15 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1070,29 +1070,31 @@ function visit(f, mt::Core.MethodTable)
nothing
end
function visit(f, mc::Core.TypeMapLevel)
if mc.targ !== nothing
e = mc.targ::Vector{Any}
function avisit(f, e::Array{Any,1})
for i in 2:2:length(e)
isassigned(e, i) && visit(f, e[i])
isassigned(e, i) || continue
ei = e[i]
if ei isa Vector{Any}
for j in 2:2:length(ei)
isassigned(ei, j) || continue
visit(f, ei[j])
end
else
visit(f, ei)
end
end
end
if mc.targ !== nothing
avisit(f, mc.targ::Vector{Any})
end
if mc.arg1 !== nothing
e = mc.arg1::Vector{Any}
for i in 2:2:length(e)
isassigned(e, i) && visit(f, e[i])
end
avisit(f, mc.arg1::Vector{Any})
end
if mc.tname !== nothing
e = mc.tname::Vector{Any}
for i in 2:2:length(e)
isassigned(e, i) && visit(f, e[i])
end
avisit(f, mc.tname::Vector{Any})
end
if mc.name1 !== nothing
e = mc.name1::Vector{Any}
for i in 2:2:length(e)
isassigned(e, i) && visit(f, e[i])
end
avisit(f, mc.name1::Vector{Any})
end
mc.list !== nothing && visit(f, mc.list)
mc.any !== nothing && visit(f, mc.any)
Expand Down
8 changes: 4 additions & 4 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ typedef struct _jl_typemap_level_t {
// next split may be on Type{T} as LeafTypes then TypeName's parents up to Any
// next split may be on LeafType
// next split may be on TypeName
_Atomic(jl_array_t*) arg1; // contains LeafType
_Atomic(jl_array_t*) targ; // contains Type{LeafType}
_Atomic(jl_array_t*) name1; // contains non-abstract TypeName, for parents up to (excluding) Any
_Atomic(jl_array_t*) tname; // contains a dict of Type{TypeName}, for parents up to Any
_Atomic(jl_array_t*) arg1; // contains LeafType (in a map of non-abstract TypeName)
_Atomic(jl_array_t*) targ; // contains Type{LeafType} (in a map of non-abstract TypeName)
_Atomic(jl_array_t*) name1; // a map for a map for TypeName, for parents up to (excluding) Any
_Atomic(jl_array_t*) tname; // a map for Type{TypeName}, for parents up to (including) Any
// next a linear list of things too complicated at this level for analysis (no more levels)
_Atomic(jl_typemap_entry_t*) linear;
// finally, start a new level if the type at offs is Any
Expand Down
Loading

0 comments on commit eb4b1a7

Please sign in to comment.