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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ function require(into::Module, mod::Symbol)
full_warning_showed[] ? "" : s, "\n",
string("Loading $(mod) into $(where.name) from project dependency, ",
"future warnings for $(where.name) are suppressed.")
) _module = nothing _file = nothing
) _module = nothing _file = nothing _group = nothing
push!(modules_warned_for, where)
end
full_warning_showed[] = true
Expand Down
14 changes: 13 additions & 1 deletion base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,21 @@ function logmsg_code(_module, file, line, level, message, exs...)
push!(kwargs, Expr(:kw, Symbol(ex), esc(ex)))
end
end

# Note that it may be necessary to set `id` and `group` manually during bootstrap
id = something(id, :(log_record_id(_module, level, $exs)))
group = something(group, :(Symbol(splitext(basename(something($file, "")))[1])))
if group == nothing
group = if isdefined(Base, :basename) && isa(file, String)
# precompute if we can
QuoteNode(splitext(basename(file))[1])
else
# 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)

end
end

quote
level = $level
std_level = convert(LogLevel, level)
Expand Down