Skip to content

Commit e85abd9

Browse files
IanButterworthKristofferC
authored andcommitted
move time_imports and trace_* macros to Base but remain owned by InteractiveUtils (#56276)
This way all packages can be timed including InteractiveUtils and its deps (Base64, JuliaSyntaxHighlighting, Markdown, StyledStrings). With this PR ``` % ./julia --start=no -e "@time Base.@time_imports using REPL" 41.8 ms StyledStrings ┌ 0.1 ms JuliaSyntaxHighlighting.__init__() 14.2 ms JuliaSyntaxHighlighting 1.0 ms Base64 ┌ 0.0 ms Markdown.__init__() 9.6 ms Markdown 2.2 ms InteractiveUtils 0.3 ms Unicode ┌ 0.0 ms REPL.REPLCompletions.__init__() ├ 0.0 ms REPL.__init__() 95.7 ms REPL 0.225907 seconds (290.95 k allocations: 16.761 MiB) ``` Otherwise ``` % ./julia --start=no -e "using InteractiveUtils; @time @time_imports using REPL" 0.5 ms Unicode ┌ 0.0 ms REPL.REPLCompletions.__init__() ├ 0.1 ms REPL.__init__() 107.5 ms REPL 0.127016 seconds (164.18 k allocations: 9.199 MiB) ``` Also the `@trace_compile` and `@trace_dispatch` macros for the same reason. (cherry picked from commit ab22f98)
1 parent e6679e1 commit e85abd9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

base/timing.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,16 @@ macro timed(ex)
506506
(value=val, time=elapsedtime/1e9, bytes=diff.allocd, gctime=diff.total_time/1e9, gcstats=diff)
507507
end
508508
end
509+
510+
# Exported, documented, and tested in InteractiveUtils
511+
# here so it's possible to time/trace all imports, including InteractiveUtils and its deps
512+
macro time_imports(ex)
513+
quote
514+
try
515+
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
516+
$(esc(ex))
517+
finally
518+
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
519+
end
520+
end
521+
end

stdlib/InteractiveUtils/src/macros.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import Base: typesof, insert!, replace_ref_begin_end!, infer_effects
66

7+
# defined in Base so it's possible to time all imports, including InteractiveUtils and its deps
8+
# via. `Base.@time_imports` etc.
9+
import Base: @time_imports
10+
711
separate_kwargs(args...; kwargs...) = (args, values(kwargs))
812

913
"""
@@ -236,17 +240,6 @@ macro code_lowered(ex0...)
236240
end
237241
end
238242

239-
macro time_imports(ex)
240-
quote
241-
try
242-
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
243-
$(esc(ex))
244-
finally
245-
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
246-
end
247-
end
248-
end
249-
250243
"""
251244
@functionloc
252245

0 commit comments

Comments
 (0)