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

remove error log pre-allocation and add benchmark #89

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

dillonstreator
Copy link
Contributor

This PR removes errorLog slice pre-allocation with the assumption that most calls to retry.Do don't actually require retry. If this is wishful thinking, please let me know. Aside from the readability win, the benchmarks that I added show improvement around allocations & cpu cycles when no errors are encountered, as expected.

Here are the results of the benchmarks that this PR introduces:

$ go test -benchmem -run=^$ -bench ^BenchmarkDo github.com/avast/retry-go/v4 > old.txt

goos: darwin
goarch: amd64
pkg: github.com/avast/retry-go/v4
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkDo-16            	       3	 420393029 ns/op	    2197 B/op	      33 allocs/op
BenchmarkDoNoErrors-16    	 5136325	       230.7 ns/op	     368 B/op	       5 allocs/op
PASS
ok  	github.com/avast/retry-go/v4	4.331s
$ go test -benchmem -run=^$ -bench ^BenchmarkDo github.com/avast/retry-go/v4 > new.txt

goos: darwin
goarch: amd64
pkg: github.com/avast/retry-go/v4
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkDo-16            	       3	 372840109 ns/op	    2568 B/op	      38 allocs/op
BenchmarkDoNoErrors-16    	 7106366	       163.9 ns/op	     208 B/op	       4 allocs/op
PASS
ok  	github.com/avast/retry-go/v4	2.902s
$ benchstat old.txt new.txt

goos: darwin
goarch: amd64
pkg: github.com/avast/retry-go/v4
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
              │   old.txt    │                new.txt                │
              │    sec/op    │    sec/op     vs base                 │
Do-16           420.4m ± ∞ ¹   372.8m ± ∞ ¹        ~ (p=1.000 n=1) ²
DoNoErrors-16   230.7n ± ∞ ¹   163.9n ± ∞ ¹        ~ (p=1.000 n=1) ²
geomean         311.4µ         247.2µ        -20.62%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

              │    old.txt    │                new.txt                 │
              │     B/op      │     B/op       vs base                 │
Do-16           2.146Ki ± ∞ ¹   2.508Ki ± ∞ ¹        ~ (p=1.000 n=1) ²
DoNoErrors-16     368.0 ± ∞ ¹     208.0 ± ∞ ¹        ~ (p=1.000 n=1) ²
geomean           899.2           730.9        -18.72%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

              │   old.txt   │               new.txt               │
              │  allocs/op  │  allocs/op   vs base                │
Do-16           33.00 ± ∞ ¹   38.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
DoNoErrors-16   5.000 ± ∞ ¹   4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean         12.85         12.33        -4.02%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

Copy link
Collaborator

@JaSei JaSei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and code is clearer. Thank you for the PR.

@JaSei JaSei merged commit 7855000 into avast:master Aug 3, 2023
@JaSei JaSei mentioned this pull request Aug 3, 2023
kodiakhq bot referenced this pull request in cloudquery/plugin-pb-go Sep 1, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/avast/retry-go/v4](https://github.com/avast/retry-go) | require | minor | `v4.3.4` -> `v4.5.0` |

---

### Release Notes

<details>
<summary>avast/retry-go (github.com/avast/retry-go/v4)</summary>

### [`v4.5.0`](https://github.com/avast/retry-go/releases/tag/v4.5.0)

[Compare Source](https://github.com/avast/retry-go/compare/4.4.0...4.5.0)

#### What's Changed

-   Allow last error to be returned with context error by [@&#8203;willdot](https://github.com/willdot) in [https://github.com/avast/retry-go/pull/96](https://github.com/avast/retry-go/pull/96)

#### New Contributors

-   [@&#8203;willdot](https://github.com/willdot) made their first contribution in [https://github.com/avast/retry-go/pull/96](https://github.com/avast/retry-go/pull/96)

**Full Changelog**: avast/retry-go@4.4.0...v4.5.0

### [`v4.4.0`](https://github.com/avast/retry-go/releases/tag/v4.4.0): (generic support)

[Compare Source](https://github.com/avast/retry-go/compare/4.3.4...4.4.0)

#### What's Changed

-   Go versions by [@&#8203;JaSei](https://github.com/JaSei) in [https://github.com/avast/retry-go/pull/97](https://github.com/avast/retry-go/pull/97)
-   fix: markdown code block format by [@&#8203;mrtc0](https://github.com/mrtc0) in [https://github.com/avast/retry-go/pull/93](https://github.com/avast/retry-go/pull/93)
-   remove error log pre-allocation and add benchmark by [@&#8203;dillonstreator](https://github.com/dillonstreator) in [https://github.com/avast/retry-go/pull/89](https://github.com/avast/retry-go/pull/89)
-   Add DoWithData function by [@&#8203;craigpastro](https://github.com/craigpastro) in [https://github.com/avast/retry-go/pull/91](https://github.com/avast/retry-go/pull/91)

#### New Contributors

-   [@&#8203;mrtc0](https://github.com/mrtc0) made their first contribution in [https://github.com/avast/retry-go/pull/93](https://github.com/avast/retry-go/pull/93)
-   [@&#8203;dillonstreator](https://github.com/dillonstreator) made their first contribution in [https://github.com/avast/retry-go/pull/89](https://github.com/avast/retry-go/pull/89)
-   [@&#8203;craigpastro](https://github.com/craigpastro) made their first contribution in [https://github.com/avast/retry-go/pull/91](https://github.com/avast/retry-go/pull/91)

**Full Changelog**: avast/retry-go@4.3.4...v4.4.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on the first day of the month" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi43OC4zIiwidXBkYXRlZEluVmVyIjoiMzYuNzguMyIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
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.

2 participants