Skip to content

Conversation

@msf
Copy link

@msf msf commented Nov 15, 2025

  • API redesign: method-based retry operations

  • Migration is simple: retry.Do(func, opts...)retry.New(opts...).Do(func) (simple find & replace)

  • This change improves performance (config reuse reduces memory allocations), simplifies the API, and provides a cleaner interface

  • Renamed Config type to Retrier

  • Renamed NewConfig() to New()

  • Changed from package-level functions to methods: retry.Do(func, config)retry.New(opts...).Do(func)

  • DelayTypeFunc signature changed: func(n uint, err error, config *Config)func(n uint, err error, r *Retrier)

  • Added benchmarks

  • minor stability fix on handling "Delay(0)" or negative delay cases

The Config is pre-computed and reusable, allowing for zero allocations on happy paths and but also lower allocation on retries.

Performance improvements (baseline: v4 retry.Do(): 129ns, 4 allocs):
BenchmarkDo_ImmediateSuccess-24 69677844 18.08 ns/op 0 B/op 0 allocs/op
BenchmarkDoWithData_ImmediateSuccess-24 73470648 16.41 ns/op 0 B/op 0 allocs/op
BenchmarkDo_OneRetry-24 49 49192156 ns/op 300 B/op 6 allocs/op

- API redesign: method-based retry operations
 - Migration is simple: `retry.Do(func, opts...)` → `retry.New(opts...).Do(func)` (simple find & replace)
 - This change improves performance (config reuse reduces memory allocations), simplifies the API, and provides a cleaner interface

 - Renamed `Config` type to `Retrier`
 - Renamed `NewConfig()` to `New()`
 - Changed from package-level functions to methods: `retry.Do(func, config)` → `retry.New(opts...).Do(func)`
 - `DelayTypeFunc` signature changed: `func(n uint, err error, config *Config)` → `func(n uint, err error, r *Retrier)`
 - Added benchmarks
 - minor stability fix on handling "Delay(0)" or negative delay cases

 The Config is pre-computed and reusable, allowing for zero allocations on happy paths and but also lower allocation on retries.

Performance improvements (baseline: v4 retry.Do(): 129ns, 4 allocs):
BenchmarkDo_ImmediateSuccess-24                 69677844                18.08 ns/op            0 B/op          0 allocs/op
BenchmarkDoWithData_ImmediateSuccess-24         73470648                16.41 ns/op            0 B/op          0 allocs/op
BenchmarkDo_OneRetry-24                               49          49192156 ns/op             300 B/op          6 allocs/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant