gmurphy-cogito opened a new pull request, #1374:
URL: https://github.com/apache/pulsar-client-go/pull/1374

   ### Motivation
   
   Previously, calls to methods such as `(*slogWrapper).Debug` and 
`(*slogWrapper).Debugf` always resulted in calls to `fmt.Sprint` and 
`fmt.Sprintf` respectively, regardless of whether the log level in question was 
even enabled. Calls to `fmt.Sprintf` in particular can be costly from a 
performance standpoint.
   
   We saw this resulting in significant performance impact in production 
instances, due to calls to `(*slogWrapper).Debug` even though debug logging was 
disabled.
   
   ### Modifications
   
   This change prevents such calls unless the log level in question is 
currently enabled. Benchmarks on an Apple M3 Max result in a ~7x speed 
improvement in 'f' method variants when the log level in question is disabled:
   
       BenchmarkDebugfNoLvlCheckWritten-14               1755528               
676.3 ns/op           232 B/op          5 allocs/op
       BenchmarkDebugfLvlCheckWritten-14                 1789832               
668.6 ns/op           232 B/op          5 allocs/op
       BenchmarkDebugfNoLvlCheckUnwritten-14             3885044               
307.9 ns/op           232 B/op          5 allocs/op
       BenchmarkDebugfLvlCheckUnwritten-14              29590905                
41.72 ns/op           24 B/op          1 allocs/op
       BenchmarkDebugNoLvlCheckWritten-14                1808078               
667.2 ns/op           232 B/op          5 allocs/op
       BenchmarkDebugLvlCheckWritten-14                  1777320               
670.4 ns/op           232 B/op          5 allocs/op
       BenchmarkDebugNoLvlCheckUnwritten-14             29176137                
41.18 ns/op           24 B/op          1 allocs/op
       BenchmarkDebugLvlCheckUnwritten-14               29249030                
41.43 ns/op           24 B/op          1 allocs/op
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change is already covered by existing tests, such as those in 
`pulsar/log/wrapper_slog_test.go` which confirm logs are output when the 
corresponding log level is enabled.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API: no
     - The schema: no
     - The default values of configurations: no
     - The wire protocol: no
   
   ### Documentation
   
     - Does this pull request introduce a new feature? no


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to