Skip to content
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

Improve performance of logging macros #28289

Merged
merged 1 commit into from
Jul 27, 2018
Merged

Improve performance of logging macros #28289

merged 1 commit into from
Jul 27, 2018

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Jul 26, 2018

Improve #28147

@maleadt maleadt added performance Must go faster logging The logging framework labels Jul 26, 2018
base/logging.jl Outdated
group = if isdefined(Base, :basename) && isa(file, String)
QuoteNode(splitext(basename(something(file, "")))[1])
else
:(Symbol(splitext(basename(something($file, "")))[1]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe memoize this in addition or instead?

Ref = Ref{Symbol}()
:(isassigned($Ref) ? $Ref[] : ($Ref[] = ...))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added.

base/logging.jl Outdated
@@ -369,9 +375,10 @@ function current_logstate()
end

# helper function to get the current logger, if enabled for the specified message type
@noinline function current_logger_for_env(std_level::LogLevel, group, _module)
function current_logger_for_env(std_level::LogLevel, group, _module)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want this to inline. It'll bloat code everywhere, but won't improve performance

Copy link
Member Author

@maleadt maleadt Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with BenchmarkTools, removing @noinline is faster, 75 vs 80 ns.
Isn't the main bloat in env_override_minlevel anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course it'll look faster on a synthetic benchmark – it's doing strictly less work, assuming all of your code fits in the processor cache. I'm surprised the hasenv check here makes a difference though. That's essentially all that env_override_minlevel is doing, maybe it should have an explicit isempty(debug) && return, in case codegen isn't able to handle our x == "" call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with a slightly less synthetic benchmark, but OK I get your point.
I had assumed a difference between haskey and getindex; I'll have a closer look.

base/logging.jl Outdated
if group == nothing
group = if isdefined(Base, :basename) && isa(file, String)
# precompute if we can
QuoteNode(splitext(basename(something(file, "")))[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file is a String, the something call is unnecessary

# memoized run-time execution
ref = Ref{Symbol}()
:(isassigned($ref) ? $ref[]
: $ref[] = Symbol(splitext(basename(something($file, "")))[1]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need parens around the assignment (currently, this is (a ? b : c) = d)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind, I forgot the precedence here are special:

julia> :(w = x ? y = 1 : z = 2)
:(w = if x
          y = 1
      else
          z = 2
      end)

@maleadt
Copy link
Member Author

maleadt commented Jul 26, 2018

Addressed review comments: added memoization and removed/simplified questionable improvements.

@JeffBezanson JeffBezanson merged commit b0075cb into master Jul 27, 2018
@JeffBezanson JeffBezanson deleted the tb/logging_perf branch July 27, 2018 17:15
@vtjnash vtjnash mentioned this pull request Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logging The logging framework performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants