Skip to content

Commit

Permalink
Profile: Faster data dict lookup (JuliaLang#43805)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored and LilithHafner committed Feb 22, 2022
1 parent 352a3dd commit d1e9b89
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,18 @@ function getdict(data::Vector{UInt})
end

function getdict!(dict::LineInfoDict, data::Vector{UInt})
for ip in data
# Lookup is expensive, so do it only once per ip.
haskey(dict, UInt64(ip)) && continue
st = lookup(convert(Ptr{Cvoid}, ip))
# To correct line numbers for moving code, put it in the form expected by
# Base.update_stackframes_callback[]
stn = map(x->(x, 1), st)
try Base.invokelatest(Base.update_stackframes_callback[], stn) catch end
dict[UInt64(ip)] = map(first, stn)
# we don't want metadata here as we're just looking up ips
unique_data_itr = Iterators.unique(has_meta(data) ? strip_meta(data) : data)
foreach(ip -> dict[UInt64(ip)] = StackFrame[], unique_data_itr)
@sync for ip in unique_data_itr
Threads.@spawn begin
st = lookup(convert(Ptr{Cvoid}, ip))
# To correct line numbers for moving code, put it in the form expected by
# Base.update_stackframes_callback[]
stn = map(x->(x, 1), st)
try Base.invokelatest(Base.update_stackframes_callback[], stn) catch end
dict[UInt64(ip)] = map(first, stn)
end
end
return dict
end
Expand Down

0 comments on commit d1e9b89

Please sign in to comment.