ronantakizawa/codereview-bench huggingface dataset:
Repository: uber-go/zap
File: exp/zapslog/example_test.go (Go)

Code before:
type Password string

func (p Password) LogValue() slog.Value {
	return slog.StringValue("REDACTED")
}

func Example_slog() {
	logger := zap.NewExample(zap.IncreaseLevel(zap.InfoLevel))
	defer logger.Sync()

	sl := slog.New(zapslog.NewHandler(logger.Core()))
	ctx := context.Background()

	sl.Info("user", "name", "Al", "secret", Password("secret"))
	sl.Error("oops", "err", net.ErrClosed, "status", 500)
	sl.LogAttrs(ctx, slog.LevelError, "oops",
		slog.Any("err", net.ErrClosed), slog.Int("status", 500))
	sl.Info("message",
		slog.Group("group",
			slog.Float64("pi", 3.14),
			slog.Duration("1min", time.Minute),
		),
	)
	sl.WithGroup("s").LogAttrs(ctx, slog.LevelWarn, "warn", slog.Uint64("u", 1), slog.Any("m", map[string]any{
		"foo": "bar",
	}))
	sl.LogAttrs(ctx, slog.LevelDebug, "not show up")

	// Output:
	// {"level":"info","msg":"user","name":"Al","secret":"REDACTED"}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"info","msg":"message","group":{"pi":3.14,"1min":"1m0s"}}
	// {"level":"warn","msg":"warn","s":{"u":1,"m":{"foo":"bar"}}}
}


Review comment (suggestion):
style nit: all params on one line, or each on their own line
```suggestion
	sl.WithGroup("s").LogAttrs(
		ctx,
		slog.LevelWarn,
		"warn", // message
		slog.Uint64("u", 1),
		slog.Any("m", map[string]any{
			"foo": "bar",
		}),
	)
```

Code after:

func (p Password) LogValue() slog.Value {
	return slog.StringValue("REDACTED")
}

func Example_slog() {
	logger := zap.NewExample(zap.IncreaseLevel(zap.InfoLevel))
	defer logger.Sync()

	sl := slog.New(zapslog.NewHandler(logger.Core()))
	ctx := context.Background()

	sl.Info("user", "name", "Al", "secret", Password("secret"))
	sl.Error("oops", "err", net.ErrClosed, "status", 500)
	sl.LogAttrs(
		ctx,
		slog.LevelError,
		"oops",
		slog.Any("err", net.ErrClosed),
		slog.Int("status", 500),
	)
	sl.Info("message",
		slog.Group("group",
			slog.Float64("pi", 3.14),
			slog.Duration("1min", time.Minute),
		),
	)
	sl.WithGroup("s").LogAttrs(
		ctx,
		slog.LevelWarn,
		"warn msg", // message
		slog.Uint64("u", 1),
		slog.Any("m", map[string]any{
			"foo": "bar",
		}))
	sl.LogAttrs(ctx, slog.LevelDebug, "not show up")

	// Output:
	// {"level":"info","msg":"user","name":"Al","secret":"REDACTED"}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"info","msg":"message","group":{"pi":3.14,"1min":"1m0s"}}
	// {"level":"warn","msg":"warn msg","s":{"u":1,"m":{"foo":"bar"}}}
}
Repository: uber-go/zap
File: exp/zapslog/example_test.go (Go)

Code before:
	"net"
	"time"

	"go.uber.org/zap"
	"golang.org/x/exp/slog"

	"go.uber.org/zap/exp/zapslog"
)

type Password string

func (p Password) LogValue() slog.Value {
	return slog.StringValue("REDACTED")
}

func Example_slog() {
	logger := zap.NewExample(zap.IncreaseLevel(zap.InfoLevel))
	defer logger.Sync()

	sl := slog.New(zapslog.NewHandler(logger.Core()))
	ctx := context.Background()

	sl.Info("user", "name", "Al", "secret", Password("secret"))
	sl.Error("oops", "err", net.ErrClosed, "status", 500)
	sl.LogAttrs(ctx, slog.LevelError, "oops",
		slog.Any("err", net.ErrClosed), slog.Int("status", 500))
	sl.Info("message",
		slog.Group("group",
			slog.Float64("pi", 3.14),
			slog.Duration("1min", time.Minute),
		),
	)
	sl.WithGroup("s").LogAttrs(ctx, slog.LevelWarn, "warn", slog.Uint64("u", 1), slog.Any("m", map[string]any{
		"foo": "bar",
	}))
	sl.LogAttrs(ctx, slog.LevelDebug, "not show up")

	// Output:
	// {"level":"info","msg":"user","name":"Al","secret":"REDACTED"}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"info","msg":"message","group":{"pi":3.14,"1min":"1m0s"}}
	// {"level":"warn","msg":"warn","s":{"u":1,"m":{"foo":"bar"}}}
}


Review comment (suggestion):
style nit: all params on one line, or each on their own line
```suggestion
	sl.LogAttrs(
		ctx,
		slog.LevelError,
		"oops", // message
		slog.Any("err", net.ErrClosed),
		slog.Int("status", 500),
	)
```

Code after:
	"net"
	"time"

	"go.uber.org/zap"
	"go.uber.org/zap/exp/zapslog"
	"golang.org/x/exp/slog"
)

type Password string

func (p Password) LogValue() slog.Value {
	return slog.StringValue("REDACTED")
}

func Example_slog() {
	logger := zap.NewExample(zap.IncreaseLevel(zap.InfoLevel))
	defer logger.Sync()

	sl := slog.New(zapslog.NewHandler(logger.Core()))
	ctx := context.Background()

	sl.Info("user", "name", "Al", "secret", Password("secret"))
	sl.Error("oops", "err", net.ErrClosed, "status", 500)
	sl.LogAttrs(
		ctx,
		slog.LevelError,
		"oops",
		slog.Any("err", net.ErrClosed),
		slog.Int("status", 500),
	)
	sl.Info("message",
		slog.Group("group",
			slog.Float64("pi", 3.14),
			slog.Duration("1min", time.Minute),
		),
	)
	sl.WithGroup("s").LogAttrs(
		ctx,
		slog.LevelWarn,
		"warn msg", // message
		slog.Uint64("u", 1),
		slog.Any("m", map[string]any{
			"foo": "bar",
		}))
	sl.LogAttrs(ctx, slog.LevelDebug, "not show up")

	// Output:
	// {"level":"info","msg":"user","name":"Al","secret":"REDACTED"}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"error","msg":"oops","err":"use of closed network connection","status":500}
	// {"level":"info","msg":"message","group":{"pi":3.14,"1min":"1m0s"}}
Repository: uber-go/zap
File: internal/pool/pool.go (Go)

Code before:
type Pool[T any] struct {
	pool sync.Pool
	ctor Constructor[T]
}

// New returns a new [Pool] for T, and will use ctor to construct new Ts when
// the pool is empty.
func New[T any](ctor Constructor[T]) *Pool[T] {
	return &Pool[T]{
		pool: sync.Pool{
			New: func() any {
				return ctor()
			},
		},
		ctor: ctor,
	}
}

// Get gets a new T from the pool, or creates a new one if the pool is empty.
func (p *Pool[T]) Get() T {
	if x, ok := p.pool.Get().(T); ok {
		return x
	}

	// n.b. This branch is effectively unreachable.
	return p.ctor()
}

// Put puts x into the pool.
func (p *Pool[T]) Put(x T) {
	p.pool.Put(x)
}


Review comment (bug):
Maybe we should drop the unreachable branch.
A failure here means a catastrophic bug.
Perhaps a simple panicking cast is sufficient:
```suggestion
	return p.pool.Get().(T)
```

Code after:
// pointer types.
type Pool[T any] struct {
	pool sync.Pool
}

// New returns a new [Pool] for T, and will use fn to construct new Ts when
// the pool is empty.
func New[T any](fn func() T) *Pool[T] {
	return &Pool[T]{
		pool: sync.Pool{
			New: func() any {
				return fn()
			},
		},
	}
}

// Get gets a T from the pool, or creates a new one if the pool is empty.
func (p *Pool[T]) Get() T {
	return p.pool.Get().(T)
}

// Put returns x into the pool.
func (p *Pool[T]) Put(x T) {
	p.pool.Put(x)
}
Repository: uber-go/zap
File: internal/pool/pool.go (Go)

Code before:
}

// New returns a new [Pool] for T, and will use ctor to construct new Ts when
// the pool is empty.
func New[T any](ctor Constructor[T]) *Pool[T] {
	return &Pool[T]{
		pool: sync.Pool{
			New: func() any {
				return ctor()
			},
		},
		ctor: ctor,
	}
}

// Get gets a new T from the pool, or creates a new one if the pool is empty.
func (p *Pool[T]) Get() T {
	if x, ok := p.pool.Get().(T); ok {
		return x
	}

	// n.b. This branch is effectively unreachable.
	return p.ctor()
}

// Put puts x into the pool.
func (p *Pool[T]) Put(x T) {
	p.pool.Put(x)
}


Review comment (suggestion):
nit:

```suggestion
// Put returns a value to the pool.
```

(I mean, there's nothing stopping someone from putting a non-pool-generated value into the pool, but I figure primary usage is to put values made by Get() back.)

Code after:
// Copyright (c) 2023 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// Package pool provides internal pool utilities.
package pool

import (
	"sync"
)

// A Pool is a generic wrapper around [sync.Pool] to provide strongly-typed
// object pooling.
//
// Note that SA6002 (ref: https://staticcheck.io/docs/checks/#SA6002) will
// not be detected, so all internal pool use must take care to only store
// pointer types.
type Pool[T any] struct {
	pool sync.Pool
}

// New returns a new [Pool] for T, and will use fn to construct new Ts when
// the pool is empty.
func New[T any](fn func() T) *Pool[T] {
	return &Pool[T]{
		pool: sync.Pool{
			New: func() any {
				return fn()
			},
		},
	}
}

// Get gets a T from the pool, or creates a new one if the pool is empty.
func (p *Pool[T]) Get() T {
	return p.pool.Get().(T)
}

// Put returns x into the pool.
func (p *Pool[T]) Put(x T) {
	p.pool.Put(x)
}
Repository: uber-go/zap
File: logger_bench_test.go (Go)

Code before:
				&ztest.Discarder{},
				DebugLevel,
			),
		)
		key = "some-long-string-longer-than-16"
	)

	tests := []struct {
		name   string
		typed  func() Field
		anyArg any
	}{
		{
			name:   "string",
			typed:  func() Field { return String(key, "yet-another-long-string") },
			anyArg: "yet-another-long-string",
		},
		{
			name:   "stringer",
			typed:  func() Field { return Stringer(key, InfoLevel) },
			anyArg: InfoLevel,
		},
	}

	for _, tt := range tests {
		b.Run(tt.name+"-typ-no-logger", func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				f := tt.typed()
				runtime.KeepAlive(f)
			}
		})
		b.Run(tt.name+"-any-no-logger", func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				f := Any(key, tt.anyArg)
				runtime.KeepAlive(f)
			}
		})
		b.Run(tt.name+"-typ-logger", func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				logger.Info("", tt.typed())
			}
		})
		b.Run(tt.name+"-any-logger", func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				logger.Info("", Any(key, tt.anyArg))
			}
		})
		b.Run(tt.name+"-typ-logger-go", func(b *testing.B) {
			wg := sync.WaitGroup{}
			wg.Add(b.N)
			b.ResetTimer()

Review comment (suggestion):
rather than appending the names, can we use a nested benchmark here? e.g.,
```go
b.Run(tt.name, func(b *testing.B) {
  b.Run("only field", func(b *testing.B) { ... }
}) 
```

optionally, i'd even group together the types of benchmarks together,

```go
b.Run(tt.name, func(b *testing.B) {
  b.Run("only field", func(b *testing.B) {
    b.Run("typed", func(b *testing.B) { .. use zap.<Typed>.. }
    b.Run("any", func(b *testing.B) { .. use zap.Any .. }
  }
}) 
```

That'll make the output easier to parse and group together the things you want to compare

Code after:
		b.Run(tt.name, func(b *testing.B) {
			b.Run("field-only", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						f := tt.typed()
						runtime.KeepAlive(f)
					})
				})
				b.Run("any", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						f := Any(key, tt.anyArg)
						runtime.KeepAlive(f)
					})
				})
			})
			b.Run("log", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						log.Info("", tt.typed())
					})
				})
				b.Run("any", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						log.Info("", Any(key, tt.anyArg))
					})
				})
			})
			b.Run("log-go", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						var wg sync.WaitGroup
						wg.Add(1)
						go func() {
							log.Info("", tt.typed())
							wg.Done()
						}()
						wg.Wait()
					})
				})
				b.Run("any", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						var wg sync.WaitGroup
						wg.Add(1)
						go func() {
							log.Info("", Any(key, tt.anyArg))
							wg.Done()
						}()
						wg.Wait()
					})
				})
			})
Repository: uber-go/zap
File: logger_bench_test.go (Go)

Code before:
	// Don't include allocating these helper slices in the benchmark. Since
	// access to them isn't synchronized, we can't run the benchmark in
	// parallel.
	first := make([]Field, batchSize)
	second := make([]Field, batchSize)
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		for i := 0; i < batchSize; i++ {
			// We're duplicating keys, but that doesn't affect performance.
			first[i] = Int("foo", i)
			second[i] = Int("foo", i+batchSize)
		}
		logger.With(first...).Info("Child loggers with lots of context.", second...)
	}
}

func dummy(wg *sync.WaitGroup, s string, i int) string {
	if i == 0 {
		wg.Wait()
		return "1" + s
	}
	return dummy(wg, s, i-1)
}

func stackGrower(n int) *sync.WaitGroup {
	wg := sync.WaitGroup{}
	wg.Add(1)

	go dummy(&wg, "hi", n)
	return &wg
}

func BenchmarkAny(b *testing.B) {
	var (
		logger = New(
			zapcore.NewCore(
				zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
				&ztest.Discarder{},
				DebugLevel,
			),
		)
		key = "some-long-string-longer-than-16"
	)

	tests := []struct {
		name   string
		typed  func() Field
		anyArg any
	}{
		{

Review comment (suggestion):
can we rename this to call out that it's starting other goroutines with some stack size since it seemed like the goal of this function was to increase the size of the current stack, which isn't what it does

Code after:
	// Don't include allocating these helper slices in the benchmark. Since
	// access to them isn't synchronized, we can't run the benchmark in
	// parallel.
	first := make([]Field, batchSize)
	second := make([]Field, batchSize)
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		for i := 0; i < batchSize; i++ {
			// We're duplicating keys, but that doesn't affect performance.
			first[i] = Int("foo", i)
			second[i] = Int("foo", i+batchSize)
		}
		logger.With(first...).Info("Child loggers with lots of context.", second...)
	}
}

func BenchmarkAny(b *testing.B) {
	key := "some-long-string-longer-than-16"

	tests := []struct {
		name   string
		typed  func() Field
		anyArg any
	}{
		{
			name:   "string",
			typed:  func() Field { return String(key, "yet-another-long-string") },
			anyArg: "yet-another-long-string",
		},
		{
			name:   "stringer",
			typed:  func() Field { return Stringer(key, InfoLevel) },
			anyArg: InfoLevel,
		},
	}

	for _, tt := range tests {
		b.Run(tt.name, func(b *testing.B) {
			b.Run("field-only", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						f := tt.typed()
						runtime.KeepAlive(f)
					})
				})
				b.Run("any", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						f := Any(key, tt.anyArg)
						runtime.KeepAlive(f)
					})
Repository: uber-go/zap
File: logger_bench_test.go (Go)

Code before:
			first[i] = Int("foo", i)
			second[i] = Int("foo", i+batchSize)
		}
		logger.With(first...).Info("Child loggers with lots of context.", second...)
	}
}

func dummy(wg *sync.WaitGroup, s string, i int) string {
	if i == 0 {
		wg.Wait()
		return "1" + s
	}
	return dummy(wg, s, i-1)
}

// increaseAvgStack starts a background goroutine with a variable
// stack size. The goal is to move the average stack size higher,
// since https://go-review.googlesource.com/c/go/+/345889 this affects
// goroutine starting stack size.
func increaseAvgStack(n int) *sync.WaitGroup {
	wg := sync.WaitGroup{}
	wg.Add(1)

	go dummy(&wg, "hi", n)
	return &wg
}

func BenchmarkAny(b *testing.B) {
	key := "some-long-string-longer-than-16"

	tests := []struct {
		name   string
		typed  func() Field
		anyArg any
	}{
		{
			name:   "string",
			typed:  func() Field { return String(key, "yet-another-long-string") },
			anyArg: "yet-another-long-string",
		},
		{
			name:   "stringer",
			typed:  func() Field { return Stringer(key, InfoLevel) },
			anyArg: InfoLevel,
		},
	}

	for _, tt := range tests {
		b.Run(tt.name, func(b *testing.B) {
			b.Run("field-only", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {

Review comment (suggestion):
We can use a simple `var data[8000]byte` to grow the stack size. 
```go
func growAvgStack() {
	var wg sync.WaitGroup
	block := make(chan struct{})
	for i := 0; i < 1000; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()

			// Effectively the minimum size for the starting goroutine size.
			var data [8000]byte
			<-block
			runtime.KeepAlive(data)
		}()
	}

	close(block)
	wg.Wait()
}
```

Verified that it works by reading + printing the starting stack size of `metrics.Sample{Name: "/gc/stack/starting-size:bytes"}`

https://go.dev/play/p/3MFl3S7Zz-A

Code after:
			first[i] = Int("foo", i)
			second[i] = Int("foo", i+batchSize)
		}
		logger.With(first...).Info("Child loggers with lots of context.", second...)
	}
}

func BenchmarkAny(b *testing.B) {
	key := "some-long-string-longer-than-16"

	tests := []struct {
		name   string
		typed  func() Field
		anyArg any
	}{
		{
			name:   "string",
			typed:  func() Field { return String(key, "yet-another-long-string") },
			anyArg: "yet-another-long-string",
		},
		{
			name:   "stringer",
			typed:  func() Field { return Stringer(key, InfoLevel) },
			anyArg: InfoLevel,
		},
	}

	for _, tt := range tests {
		b.Run(tt.name, func(b *testing.B) {
			b.Run("field-only", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						f := tt.typed()
						runtime.KeepAlive(f)
					})
				})
				b.Run("any", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						f := Any(key, tt.anyArg)
						runtime.KeepAlive(f)
					})
				})
			})
			b.Run("log", func(b *testing.B) {
				b.Run("typed", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
						log.Info("", tt.typed())
					})
				})
				b.Run("any", func(b *testing.B) {
					withBenchedLogger(b, func(log *Logger) {
Repository: uber-go/zap
File: logger_bench_test.go (Go)

Code before:
		zapcore.NewCore(
			zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
			&ztest.Discarder{},
			InfoLevel,
		),
		AddCaller(),
		AddStacktrace(WarnLevel),
	)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			logger.Warn("Caller and stacktrace.")
		}
	})
}
func Benchmark5WithsUsed(b *testing.B) {
	withBenchedLogger(b, func(log *Logger) {
		make5ChainedChildLoggers(log).Info("used")
	})
}

func Benchmark5WithsNotUsed(b *testing.B) {
	withBenchedLogger(b, func(log *Logger) {
		l := make5ChainedChildLoggers(log)
		runtime.KeepAlive(l)
	})
}

func make5ChainedChildLoggers(log *Logger) *Logger {
	return log.With(String("k1", "v1")).
		With(String("k2", "v2")).
		With(String("k3", "v3")).
		With(String("k4", "v4")).
		With(String("k5", "v5"))
}

func Benchmark10Fields(b *testing.B) {
	withBenchedLogger(b, func(log *Logger) {
		log.Info("Ten fields, passed at the log site.",
			Int("one", 1),
			Int("two", 2),
			Int("three", 3),
			Int("four", 4),
			Int("five", 5),
			Int("six", 6),
			Int("seven", 7),
			Int("eight", 8),
			Int("nine", 9),
			Int("ten", 10),
		)
	})

Review comment (suggestion):
Instead of hard-coding the 5, how about something like this?

```go
func benchmarkWithUsed(b *testing.B, N int, use bool) {
  keys := make([]string, N)
  values := make([]string, N)
  for i := 0; i < N; i++ {
    keys[i] = "k" + strconv.Itoa(i)
    values[i] = "v" + strconv.Itoa(i)
  }

  b.ResetTimers()

  withBenchedLogger(b, func(log *Logger) {
    for i := 0; i < N; i++ {
      log = log.With(String(keys[i], values[i]))
    }
    if use {
      log.Info("used")
    } else {
      runtime.KeepAlive(log)
    }
  })
}
```

Code after:
	logger := New(
		zapcore.NewCore(
			zapcore.NewJSONEncoder(NewProductionConfig().EncoderConfig),
			&ztest.Discarder{},
			InfoLevel,
		),
		AddCaller(),
		AddStacktrace(WarnLevel),
	)
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			logger.Warn("Caller and stacktrace.")
		}
	})
}
func Benchmark5WithsUsed(b *testing.B) {
	benchmarkWithUsed(b, 5, true)
}

// This benchmark will be used in future as a
// baseline for improving
func Benchmark5WithsNotUsed(b *testing.B) {
	benchmarkWithUsed(b, 5, false)
}

func benchmarkWithUsed(b *testing.B, N int, use bool) {
	keys := make([]string, N)
	values := make([]string, N)
	for i := 0; i < N; i++ {
		keys[i] = "k" + strconv.Itoa(i)
		values[i] = "v" + strconv.Itoa(i)
	}

	b.ResetTimer()

	withBenchedLogger(b, func(log *Logger) {
		for i := 0; i < N; i++ {
			log = log.With(String(keys[i], values[i]))
		}
		if use {
			log.Info("used")
			return
		}
		runtime.KeepAlive(log)
	})
}

func Benchmark10Fields(b *testing.B) {
	withBenchedLogger(b, func(log *Logger) {
		log.Info("Ten fields, passed at the log site.",
Repository: uber-go/zap
File: exp/zapslog/options.go (Go)

Code before:
		h.name = name
	})
}

// WithCaller configures the Logger to annotate each message with the filename,
// line number, and function name of Zap's caller, or not, depending on the
// value of enabled.
func WithCaller(enabled bool) Option {
	return optionFunc(func(handler *Handler) {
		handler.addCaller = enabled
	})
}

// AddCallerSkip increases the number of callers skipped by caller annotation
// (as enabled by the AddCaller option). When building wrappers around the
// Logger and SugaredLogger, supplying this Option prevents zap from always
// reporting the wrapper code as the caller.
func AddCallerSkip(skip int) Option {
	return optionFunc(func(log *Handler) {
		log.callerSkip += skip
	})
}

// AddStacktrace configures the Logger to record a stack trace for all messages at
// or above a given level.
func AddStacktrace(lvl zapcore.LevelEnabler) Option {
	return optionFunc(func(log *Handler) {
		log.addStack = lvl
	})
}


Review comment (suggestion):
Just thinking out loud (would love your opinion on this, @zekth):
I wonder if this should be a slog Level instead. Or a new zapslog.LevelEnabler interface based on slog.Level.

```go
type LevelEnabler interface{ Enabled(context.Context, Level) bool }
```

The reasoning is this: the result of zapslog.NewHandler is a slog Handler. It talks in the language of slog. 

Code after:
		h.name = name
	})
}

// WithCaller configures the Logger to include the filename and line number
// of the caller in log messages--if available.
func WithCaller(enabled bool) Option {
	return optionFunc(func(handler *Handler) {
		handler.addCaller = enabled
	})
}

// WithCallerSkip increases the number of callers skipped by caller annotation
// (as enabled by the [WithCaller] option).
//
// When building wrappers around the Logger,
// supplying this Option prevents Zap from always reporting
// the wrapper code as the caller.
func WithCallerSkip(skip int) Option {
	return optionFunc(func(log *Handler) {
		log.callerSkip += skip
	})
}

// AddStacktraceAt configures the Logger to record a stack trace
// for all messages at or above a given level.
func AddStacktraceAt(lvl slog.Level) Option {
	return optionFunc(func(log *Handler) {
		log.addStackAt = lvl
	})
}