-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Presence of @debug
can cause massive performance hit
#28147
Comments
Can you make an example that doesn't include |
Sure julia> function xparse(str)
Base.parse(Int, str)
end
xparse (generic function with 1 method)
julia> function xparse2(str)
@debug "xparse"
Base.parse(Int, str)
end
xparse2 (generic function with 1 method)
julia> @btime xparse("0")
38.532 ns (0 allocations: 0 bytes)
0
julia> @btime xparse2("0")
1.133 μs (13 allocations: 624 bytes)
0 |
The four lines from the expanded macro still run even even when nothing is printed. Guess those are the cause of the slowdown. Lines 298 to 301 in 299300a
Can do julia> @btime xparse("0")
42.516 ns (0 allocations: 0 bytes)
0
julia> @btime xparse2("0")
49.323 ns (0 allocations: 0 bytes)
0 |
Why is there a state where the debug log level is enabled (to the extent the fast-reject doesn't happen) but still nothing is printed? Are there separate global and local states and multiple loggers present by default? |
Precisely because of #26265, right? So you can opt in with ENV variables. |
I see; it looks like the intent of that was to allow environment variables to change the logging level at any time? It doesn't seem like that could ever perform well. Maybe only check the env vars on startup? |
Turns out most of the slowdown is due to generating a message group identifier from the sourceinfo filename by calling splitext/basename at runtime, which incidentally only happens when logging is enabled (hence the effect in #28147 (comment)). The environment override is OK optimized, and only reparses when the variable actually changes. Some timings: # base version
julia> @btime @debug "test"
704.184 ns (10 allocations: 464 bytes)
# fix group id generation
julia> @btime @debug "test"
73.424 ns (0 allocations: 0 bytes)
# optimize current_logger_for_env
julia> @btime @debug "test"
56.486 ns (0 allocations: 0 bytes)
# disable env_override_minlevel
julia> @btime @debug "test"
7.246 ns (0 allocations: 0 bytes) Is this overhead acceptable, or should we go all the way and disable that functionality? With many people doing REPL-based development, I can imagine it being useful to flip log levels at group granularity within a session.
|
Is this completely resolved by #28289? |
There's still a slowdown, but that's unavoidable. Definitely not massive anymore, so I guess this can be closed. |
These cause a real slowdown in the runtime (~20% degradation) even when DEBUG isn't enabled There are quite a few complaints about this in the forums, e.g., JuliaLang/julia#28147. It does seem to have improved, but for code like this it's still a serious regression
These cause a real slowdown in the runtime (~20% degradation) even when DEBUG isn't enabled There are quite a few complaints about this in the forums, e.g., JuliaLang/julia#28147. It does seem to have improved, but for code like this it's still a serious regression
Same code, the 1st example is with a line like
@debug "xparse Int"
in the function, the 2nd is with that line commented out.(On the bright side, my morning I dedicated to solving performance problems just got a lot easier; comment out all the debug statements!)
The text was updated successfully, but these errors were encountered: