zap icon indicating copy to clipboard operation
zap copied to clipboard

Only set entry time when entry will be logged

Open pjvds opened this issue 5 years ago • 4 comments

This pull request optimizes the Check scenario. It only sets the entry time after the decision has been made to log the entry or not. This improves performance in a disabled scenario by 63.55%.

benchmark                                           old ns/op     new ns/op     delta
BenchmarkDisabledAccumulatedContext/Zap.Check-4     20.3          7.40          -63.55%

pjvds avatar Dec 31 '18 09:12 pjvds

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Dec 31 '18 09:12 CLAassistant

Codecov Report

Merging #664 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #664   +/-   ##
=======================================
  Coverage   97.38%   97.38%           
=======================================
  Files          40       40           
  Lines        2102     2102           
=======================================
  Hits         2047     2047           
  Misses         47       47           
  Partials        8        8
Impacted Files Coverage Δ
logger.go 94.49% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 67bc79d...dfdea27. Read the comment docs.

codecov[bot] avatar Dec 31 '18 13:12 codecov[bot]

We also noticed that recording the time in high throughput scenarios was a bottleneck, basically because we had a lot of debug messages. However I'm afraid you cannot merge this change without breaking compatibility because cores such as the sampling core rely on the time information in order to check if the log entry should be printed or not. Additionally there might be other hooked cores which work in a similar way.

What we ended up doing was to wrap the debug log calls in a function which only checks the level and aborts early if possible. Of course that means that we cannot use any sampling based logging there.

fgrosse avatar Jan 01 '19 14:01 fgrosse

Is there a reason why we don't remove the sampling state to the sampling core itself, or make it not time depending but just a percentage of the logs with an atomic counter? This would mean you only pay the overhead for sampling support if the sampling core is enabled.

pjvds avatar Jan 02 '19 08:01 pjvds