You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Spend less time preparing to write log lines when the logger is disabled (#352)
* Skip some logging work when log message would be ignored
In callers like HashiCorp Terraform, the plugin logger is completely
disabled (hclog.Off) by default, but previously go-plugin would nonetheless
waste time trying to parse log lines to decide what log level to use when
calling into the logger, creating memory allocation garbage and spending
time in the JSON parser only to immediately discard the results.
The hclog.Logger API exposes information about the log level so that
callers can skip doing expensive preparation work unless it will actually
be used. We'll now use that to totally skip all of the log preparation
when the logger is completely disabled, and to skip _some_ of the work
if the log line's level is not sufficient to match the logger's level.
* Log entries use flat KVPairs, instead of slice of pointers
Previously the JSON log line parsing code would allocate separately for
each additional key/value pair in a log line. Using a flat slice of
logEntryKV instead of indirection through pointers amortizes that memory
allocation cost a little better, for a marginal decrease in allocations
per log line.
The resulting logEntryKV objects are always passed and used all together
anyway, so there is no clear advantage to splitting each into a separate
memory allocation.
0 commit comments