-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
logger: Check level before creating entry #771
Conversation
Calling `time.Now()` and creating an entry is unnecessary if the underlying core has the specified level disabled. To reduce the cost of logs at disabled levels, skip entry creation if the log level is disabled in the core. This special logic does not apply to DPanic or higher logs as they may need to panic/exit even if the entry does not cause any log to be emitted. On my machine, disabled debugging logs are 6x (~60ns to ~10ns). Fixes #770.
Codecov Report
@@ Coverage Diff @@
## master #771 +/- ##
==========================================
+ Coverage 98.19% 98.19% +<.01%
==========================================
Files 42 42
Lines 2269 2271 +2
==========================================
+ Hits 2228 2230 +2
Misses 33 33
Partials 8 8
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
new test? |
Since this is an optimization, it doesn't have any impact to the functional tests, just a performance improvement. While it is possible to write a test to check for this (we can verify at the core which methods are called), it seems like we're breaking the abstraction. |
Perhaps not a test, but perhaps we should add a benchmark for messages being discarded if we don't already have one. |
We do have existing benchmarks for this,
Will update the summary as well. |
This picks up uber-go/zap#771. Change-Id: Ic55f3fd29b0d600a3b1c87bd117f7e0a2e0fce04 Signed-off-by: Matthew Sykes <[email protected]>
This picks up uber-go/zap#771. Change-Id: Ic55f3fd29b0d600a3b1c87bd117f7e0a2e0fce04 Signed-off-by: Matthew Sykes <[email protected]>
Calling `time.Now()` and creating an entry is unnecessary if the underlying core has the specified level disabled. To reduce the cost of logs at disabled levels, skip entry creation if the log level is disabled in the core. This special logic does not apply to DPanic or higher logs as they may need to panic/exit even if the entry does not cause any log to be emitted. On my machine, disabled debugging logs are 6x (~60ns to ~10ns) based on the example in the issue. benchcmp: ``` benchmark old ns/op new ns/op delta BenchmarkDisabledWithoutFields/Zap-12 8.42 1.59 -81.12% BenchmarkDisabledWithoutFields/Zap.Check-12 8.01 1.32 -83.52% BenchmarkDisabledWithoutFields/Zap.Sugar-12 12.4 11.4 -8.06% BenchmarkDisabledWithoutFields/Zap.SugarFormatting-12 117 102 -12.82% ``` Fixes uber-go#770.
Calling
time.Now()
and creating an entry is unnecessaryif the underlying core has the specified level disabled.
To reduce the cost of logs at disabled levels, skip entry
creation if the log level is disabled in the core.
This special logic does not apply to DPanic or higher logs as
they may need to panic/exit even if the entry does not cause
any log to be emitted.
On my machine, disabled debugging logs are 6x (~60ns to ~10ns)
based on the example in the issue.
benchcmp:
Fixes #770.