improvement(log): add call stack to func on the record #14052
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Moved the stack.Caller to a func on the Record. Calling the stack multiple times every log gets expensive even when you are logging under the level defined in config. This is because the call stack will get created every time the Log() func runs on the handlers, even if the call stack is not being used.
Context
This issue came up in CDK Erigon saying the log was performing poorly in a pprof benchmark.
Issue 1: 1637
Issue 2: 1770
After running a bechmark pprof after this changeset, the call stack has gone from the flame graph and improves performance.
CDK Erigon changeset
1f4cca638da71ffec4490bf21fa84004984b3546