Skip to content

Commit ab22f98

Browse files
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.
1 parent 7d4b2b7 commit ab22f98

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

base/timing.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,38 @@ macro timed(ex)
628628
)
629629
end
630630
end
631+
632+
# Exported, documented, and tested in InteractiveUtils
633+
# here so it's possible to time/trace all imports, including InteractiveUtils and its deps
634+
macro time_imports(ex)
635+
quote
636+
try
637+
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
638+
$(esc(ex))
639+
finally
640+
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
641+
end
642+
end
643+
end
644+
645+
macro trace_compile(ex)
646+
quote
647+
try
648+
ccall(:jl_force_trace_compile_timing_enable, Cvoid, ())
649+
$(esc(ex))
650+
finally
651+
ccall(:jl_force_trace_compile_timing_disable, Cvoid, ())
652+
end
653+
end
654+
end
655+
656+
macro trace_dispatch(ex)
657+
quote
658+
try
659+
ccall(:jl_force_trace_dispatch_enable, Cvoid, ())
660+
$(esc(ex))
661+
finally
662+
ccall(:jl_force_trace_dispatch_disable, Cvoid, ())
663+
end
664+
end
665+
end

stdlib/InteractiveUtils/src/macros.jl

Lines changed: 4 additions & 33 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, @trace_compile, @trace_dispatch
10+
711
separate_kwargs(args...; kwargs...) = (args, values(kwargs))
812

913
"""
@@ -245,39 +249,6 @@ macro code_lowered(ex0...)
245249
end
246250
end
247251

248-
macro time_imports(ex)
249-
quote
250-
try
251-
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
252-
$(esc(ex))
253-
finally
254-
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
255-
end
256-
end
257-
end
258-
259-
macro trace_compile(ex)
260-
quote
261-
try
262-
ccall(:jl_force_trace_compile_timing_enable, Cvoid, ())
263-
$(esc(ex))
264-
finally
265-
ccall(:jl_force_trace_compile_timing_disable, Cvoid, ())
266-
end
267-
end
268-
end
269-
270-
macro trace_dispatch(ex)
271-
quote
272-
try
273-
ccall(:jl_force_trace_dispatch_enable, Cvoid, ())
274-
$(esc(ex))
275-
finally
276-
ccall(:jl_force_trace_dispatch_disable, Cvoid, ())
277-
end
278-
end
279-
end
280-
281252
"""
282253
@functionloc
283254

0 commit comments

Comments
 (0)