Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearch for performance: BREAKING CHANGES #42

Merged
merged 6 commits into from
May 28, 2021
Merged

Commits on Apr 22, 2021

  1. Make the benchmark not inline ther impl

    In real code, the definition of the Logger would be far away from the
    logging call-sites.  The benchmark now forces the compiler to NOT
    inline, even though it could.  It also now tests logr.Discard() and
    funcr.
    thockin committed Apr 22, 2021
    Configuration menu
    Copy the full SHA
    2a44646 View commit details
    Browse the repository at this point in the history

Commits on May 16, 2021

  1. Per-driven overhaul

    Convert Logger from an interfact to a concrete type that calls out to a
    LogSink interface.
    
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    !!                                                         !!
    !! THIS IS A BREAKING CHANGE                               !!
    !!                                                         !!
    !! Most end-users just need to recompile.                  !!
    !!                                                         !!
    !! Logging implementations need to make code changes.      !!
    !!                                                         !!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    Before:
    ```
    $ go test -bench='.' ./benchmark/
    goos: linux
    goarch: amd64
    pkg: github.com/go-logr/logr/benchmark
    cpu: Intel(R) Xeon(R) W-2135 CPU @ 3.70GHz
    BenchmarkInfoOneArg-6        	 3013077	       400.9 ns/op
    BenchmarkInfoSeveralArgs-6   	 1162088	      1039 ns/op
    BenchmarkV0Info-6            	  754347	      1418 ns/op
    BenchmarkV9Info-6            	 4605950	       267.8 ns/op
    BenchmarkError-6             	  935028	      1135 ns/op
    BenchmarkWithValues-6        	 5127631	       232.5 ns/op
    BenchmarkWithName-6          	12850569	       106.5 ns/op
    ```
    
    After:
    ```
    $ go test -bench='.' ./benchmark/
    goos: linux
    goarch: amd64
    pkg: github.com/go-logr/logr/benchmark
    cpu: Intel(R) Xeon(R) W-2135 CPU @ 3.70GHz
    BenchmarkInfoOneArg-6        	 2465788	       475.7 ns/op
    BenchmarkInfoSeveralArgs-6   	  893026	      1226 ns/op
    BenchmarkV0Info-6            	  817473	      1250 ns/op
    BenchmarkV9Info-6            	 8595180	       155.1 ns/op
    BenchmarkError-6             	 1000000	      1371 ns/op
    BenchmarkWithValues-6        	 3902214	       292.0 ns/op
    BenchmarkWithName-6          	11271037	       106.6 ns/op
    ```
    
    Logs that actually write are dominated by the cost of preparing the
    message.  Logs which do not write (e.g. `V(9)`) are faster here
    (thog glog raw is much faster still).  The main difference is the
    variadic slice setup.  This is a candidate for Go to optimize - it now
    knows that the args are only used inside the conditional (`Enabled()`),
    and when that path is not executed, it can elide that work.
    thockin committed May 16, 2021
    Configuration menu
    Copy the full SHA
    bb231ff View commit details
    Browse the repository at this point in the history
  2. Move code, fix comments

    thockin committed May 16, 2021
    Configuration menu
    Copy the full SHA
    6987102 View commit details
    Browse the repository at this point in the history
  3. simpler logr.New() signature

    thockin committed May 16, 2021
    Configuration menu
    Copy the full SHA
    000e78e View commit details
    Browse the repository at this point in the history
  4. Add LogSink.Init() mechanism

    This allows logr to pass params about internal stuff (such as the number
    of call frames it adds) to LogSink implementations.
    thockin committed May 16, 2021
    Configuration menu
    Copy the full SHA
    19480e9 View commit details
    Browse the repository at this point in the history
  5. Remove deprecated back-compat things

    DiscardLogger became a LogSink, so leaving that as a type was only
    needed for NullLogger.
    
    NullLogger can be completely replaced with Discard().
    
    InfoLogger is vestigial and since this is a breaking change anyway,
    let's kill it off.
    
    Not that Logger is a type, we do not need WithCallDepth() as a
    standalone anymore.
    thockin committed May 16, 2021
    Configuration menu
    Copy the full SHA
    68c541a View commit details
    Browse the repository at this point in the history