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

First pass at improving load times #164

Merged
merged 5 commits into from
Aug 19, 2020
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Memento"
uuid = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
license = "MIT"
authors = ["Invenia Technical Computing"]
version = "1.1.0"
version = "1.1.1"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
2 changes: 2 additions & 0 deletions src/Memento.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ include("config.jl")
include("exceptions.jl")
include("memento_test.jl")
include("deprecated.jl")
include("precompile.jl")

# Initializing at compile-time will work as long as the loggers which are added do not
# contain references to stdout.
Expand All @@ -65,4 +66,5 @@ function __init__()
Memento.register(LOGGER)
oxinabox marked this conversation as resolved.
Show resolved Hide resolved
end

_precompile_()
oxinabox marked this conversation as resolved.
Show resolved Hide resolved
end
3 changes: 2 additions & 1 deletion src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function config!(
setpropagating!(logger, propagate)
handler = DefaultHandler(
stdout,
DefaultFormatter(fmt), Dict{Symbol, Any}(:is_colorized => colorized)
DefaultFormatter(fmt),
Dict{Symbol, Any}(:is_colorized => colorized),
)
logger.handlers["console"] = handler
register(logger)
Expand Down
9 changes: 6 additions & 3 deletions src/formatters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Ex) "[{level} | {name}]: {msg}" will print message of the form
struct DefaultFormatter <: Formatter
fmt_str::AbstractString
tokens::Vector{Pair{Symbol, Bool}}
output_tz::Dates.TimeZone
output_tz::Union{Dates.TimeZone, Nothing}
Copy link
Member

@oxinabox oxinabox Aug 18, 2020

Choose a reason for hiding this comment

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

Beyond the scope of this PR maybe:
I wonder if we should have a timezone in TimeZones.jl called User or UserLocal,
which has the behavour of that having this as nothing does; where it is a caching version of localzone.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was talking to Curtis a bit about it, but I'd have to think more about how it should work and if that has some potential downfalls. Looks like this caching behaviour might be causing issues on Linux.


function DefaultFormatter(
fmt_str::AbstractString=DEFAULT_FMT_STRING,
output_tz=localzone(),
output_tz=nothing,
)
#r"(?<={).+?(?=})
tokens = map(eachmatch(r"({.+?})|(.+?)", fmt_str)) do m
Expand All @@ -45,6 +45,7 @@ struct DefaultFormatter <: Formatter
end
end


"""
format(::DefaultFormatter, ::Record) -> String

Expand Down Expand Up @@ -77,7 +78,9 @@ function format(fmt::DefaultFormatter, rec::Record)
value = string(" stack:[", join(str_frames, ", "), "]")
elseif content === :date
value = if tmp_val isa ZonedDateTime
Dates.format(astimezone(tmp_val, fmt.output_tz), DATE_FMT_STRING)
# `localzone` is expensive, so we don't call it until it is required.
tzout = fmt.output_tz === nothing ? localzone() : fmt.output_tz
Dates.format(astimezone(tmp_val, tzout), DATE_FMT_STRING)
elseif tmp_val isa DateTime
Dates.format(tmp_val, DATE_FMT_STRING)
else
Expand Down
4 changes: 4 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function _precompile_()
# Precompiling this one methods seems to cut our allocations during package loading in half.
@assert precompile(Tuple{typeof(Base.log), Memento.Logger, Memento.DefaultRecord})
end