Optimize log hot path - #4913
Conversation
…entationScopeInfo
Codecov ReportBase: 90.89% // Head: 90.93% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #4913 +/- ##
============================================
+ Coverage 90.89% 90.93% +0.03%
- Complexity 4804 4816 +12
============================================
Files 545 545
Lines 14340 14382 +42
Branches 1383 1382 -1
============================================
+ Hits 13035 13078 +43
Misses 898 898
+ Partials 407 406 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
No real problem with this optimization, but is this really on the hot path? Shouldn't people be initializing their loggers/tracers/etc once, rather than fetching them every time? |
With tracers and meters, yes. But log appender implementations use the logger name as the name of the logger, so they have to get a logger for each log record they process. Here's an example from the log4j appender. The logback and jul implementations work the same way. The appenders could implement their own cache of loggers by maintaining a map of logger name to logger, but if that's a pattern all implementations will have to do we should probably solve it in the SDK. |
ah, I see. for the appender case, that makes sense. thanks! |
* ComponentRegistry accepts name, version, schemaUrl instead of InstrumentationScopeInfo * Fix comment
Followup to #4891.
Reduces allocations on happy path by avoiding creation of extra
InstrumentationScopeInfo/InstrumentationScopeInfoBuilderinstances that aren't strictly needed. Does this by adjusting changingComponentRegistry#get(InstrumentationScopeInfo)toComponentRegistry#get(String name, @Nullable String version, @Nullable String schemaUrl, Attributes attributes), and only buildingInstrumentationScopeInfothe first time we see a component with a particular identity.Benchmark before:
Benchmark after:
Notice the significant reduction in allocation rate.