Skip to content

Commit 14154fc

Browse files
Profile: Faster data dict lookup (#43805)
1 parent de85dea commit 14154fc

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

stdlib/Profile/src/Profile.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,18 @@ function getdict(data::Vector{UInt})
349349
end
350350

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

0 commit comments

Comments
 (0)