You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix bug in @time compilation time measurement, using tryfinally macro. (#41923)
Use a tryfinally macro to ensure compile timer is closed, while maintaining scope.
This fixes a bug where an exception thrown _anywhere_, on any Task on
any thread, completely disables the compilation time measurement for any
concurrently executing `@time` blocks, without warning the user about
it.
Here are some examples of the current, broken behavior:
- Throwing (and catching) an exception disables compilation time
measurement, even though the exception didn't escape, without warning
the user - note 0 compilation time reported:
```julia
julia> @time begin
# The following exception disables compilation time measurement
try throw("ha HAH!") catch end
@eval module M ; f(x) = 2*x ; end
@eval M.f(2)
end
0.003950 seconds (2.17 k allocations: 170.093 KiB)
4
```
- Throwing an exception while the first task is sleeping disables
compilation time measurement, so this ends up incorrectly reporting 0
compilation time:
```julia
julia> f(n) = begin
# while we're sleeping, someone throws an exception somewhere else :'(
sleep(n)
@eval module M ; f(x) = 2*x ; end
@eval M.f(2)
end
f (generic function with 1 method)
julia> f(0) # warmup
WARNING: replacing module M.
4
julia> @async@time f(5)
Task (runnable) @0x000000010f2c0780
julia> throw("oh no sad")
ERROR: "oh no sad"
Stacktrace:
[1] top-level scope
@ REPL[9]:1
WARNING: replacing module M.
5.008401 seconds (1.92 k allocations: 120.515 KiB)
```
After this commit, both of those examples correctly report their
compilation time.
(cherry picked from commit 08e100b)
0 commit comments