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

[Refactor] Improve errors.Join performance #2010

Merged
merged 3 commits into from
Apr 20, 2023

Conversation

kpango
Copy link
Collaborator

@kpango kpango commented Apr 19, 2023

Description:

Since errors.Is was used to evaluate the equality of errors in errors.Join for the 0th and subsequent errors, performance problems occurred exponentially depending on the length of the errors.

By eliminating the evaluation of errors.Is, I have confirmed that performance can be improved.

❯ go test -count=3 -timeout=1h -run=NONE -bench . -benchmem
goos: linux
goarch: amd64
pkg: github.com/vdaas/vald/internal/errors
cpu: AMD Ryzen Threadripper 3990X 64-Core Processor
BenchmarkWrapLongData-128                     30          34398736 ns/op        138625268 B/op     88049 allocs/op
BenchmarkWrapLongData-128                     57          19898078 ns/op        137000936 B/op     47636 allocs/op
BenchmarkWrapLongData-128                     20          50354703 ns/op        140355950 B/op    130721 allocs/op
BenchmarkWrapShortData-128                 61291             16516 ns/op           10668 B/op         53 allocs/op
BenchmarkWrapShortData-128                 54051             19190 ns/op           10345 B/op         59 allocs/op
BenchmarkWrapShortData-128                142771              7767 ns/op           13588 B/op         30 allocs/op
BenchmarkJoinLongData-128                  36448             27727 ns/op           40963 B/op         71 allocs/op
BenchmarkJoinLongData-128                  54247             19699 ns/op           42938 B/op         48 allocs/op
BenchmarkJoinLongData-128                  34216             31447 ns/op           46316 B/op         75 allocs/op
BenchmarkJoinShortData-128               3351846               335.7 ns/op           312 B/op          0 allocs/op
BenchmarkJoinShortData-128               4782178               220.1 ns/op           309 B/op          0 allocs/op
BenchmarkJoinShortData-128               2409987               425.7 ns/op           323 B/op          1 allocs/op
BenchmarkStdWrapLongData-128                  38          27880411 ns/op        137966772 B/op     70084 allocs/op
BenchmarkStdWrapLongData-128                  38          26452982 ns/op        137953649 B/op     70085 allocs/op
BenchmarkStdWrapLongData-128                  50          20250260 ns/op        137281848 B/op     53914 allocs/op
BenchmarkStdWrapShortData-128              43831             23024 ns/op           10736 B/op         70 allocs/op
BenchmarkStdWrapShortData-128              71410             14347 ns/op           13066 B/op         47 allocs/op
BenchmarkStdWrapShortData-128              55992             18342 ns/op           10656 B/op         57 allocs/op
BenchmarkStdJoinLongData-128               93657             11985 ns/op           29765 B/op       1051 allocs/op
BenchmarkStdJoinLongData-128               13926             73825 ns/op           36024 B/op       1207 allocs/op
BenchmarkStdJoinLongData-128               11421             87668 ns/op           37639 B/op       1248 allocs/op
BenchmarkStdJoinShortData-128            1830832               549.7 ns/op           279 B/op          9 allocs/op
BenchmarkStdJoinShortData-128            1901421               552.7 ns/op           277 B/op          9 allocs/op
BenchmarkStdJoinShortData-128            1101970               917.7 ns/op           316 B/op         10 allocs/op
PASS
ok      github.com/vdaas/vald/internal/errors   873.150s

Related Issue:

Versions:

  • Go Version: 1.20.3
  • Docker Version: 20.10.8
  • Kubernetes Version: 1.22.0
  • NGT Version: 2.0.9

Checklist:

Special notes for your reviewer:

Signed-off-by: kpango <kpango@vdaas.org>
@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 💌 /changelog - replace the PR body by changelog details
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • /rebase - rebase main
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

@kpango kpango requested review from a team, hlts2 and ykadowak and removed request for a team April 19, 2023 06:18
hlts2
hlts2 previously approved these changes Apr 19, 2023
Copy link
Collaborator

@hlts2 hlts2 left a comment

Choose a reason for hiding this comment

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

LGTM

ykadowak
ykadowak previously approved these changes Apr 19, 2023
Signed-off-by: kpango <kpango@vdaas.org>
@kpango kpango dismissed stale reviews from ykadowak and hlts2 via 4044ca2 April 19, 2023 06:45
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 19, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1331c00
Status: ✅  Deploy successful!
Preview URL: https://547a7f38.vald.pages.dev
Branch Preview URL: https://refactor-errors-improve-erro.vald.pages.dev

View logs

ykadowak
ykadowak previously approved these changes Apr 19, 2023
@codecov
Copy link

codecov bot commented Apr 19, 2023

Codecov Report

Patch coverage: 16.90% and project coverage change: -0.05 ⚠️

Comparison is base (540c93a) 29.51% compared to head (1331c00) 29.46%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2010      +/-   ##
==========================================
- Coverage   29.51%   29.46%   -0.05%     
==========================================
  Files         366      366              
  Lines       34532    34559      +27     
==========================================
- Hits        10192    10184       -8     
- Misses      23917    23948      +31     
- Partials      423      427       +4     
Impacted Files Coverage Δ
internal/errors/errors.go 50.24% <0.00%> (-3.13%) ⬇️
internal/slices/slices.go 33.33% <14.28%> (-66.67%) ⬇️
internal/net/grpc/stream.go 27.21% <40.00%> (+1.86%) ⬆️

... and 7 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

hlts2
hlts2 previously approved these changes Apr 19, 2023
Copy link
Collaborator

@hlts2 hlts2 left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link
Contributor

@vdaas-ci
Copy link
Collaborator

Profile Report

typevald-agent-ngtvald-lb-gatewayvald-discoverervald-manager-index
cpu
heap
other images

@kpango kpango force-pushed the refactor/errors/improve-errors-join-performance branch from b2cdada to ccd4f81 Compare April 19, 2023 09:21

func TestSortStableFunc(t *testing.T) {
type args struct {
x []E
Copy link

Choose a reason for hiding this comment

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

21% of developers fix this issue

typecheck: undefined: E

❗❗ 2 similar findings have been found in this PR

🔎 Expand here to view all instances of this finding
File Path Line Number
internal/slices/slices_test.go 197
internal/slices/slices_test.go 279

Visit the Lift Web Console to find more details in your report.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Signed-off-by: kpango <kpango@vdaas.org>
@kpango kpango force-pushed the refactor/errors/improve-errors-join-performance branch from 66b3d38 to 1331c00 Compare April 19, 2023 09:50
return nil
}
tests := []test{
// TODO test cases
Copy link

Choose a reason for hiding this comment

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

0% of developers fix this issue

godox: internal/slices/slices_test.go:303: Line contains TODO/BUG/FIXME: "TODO test cases"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

},
*/

// TODO test cases
Copy link

Choose a reason for hiding this comment

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

0% of developers fix this issue

godox: internal/slices/slices_test.go:322: Line contains TODO/BUG/FIXME: "TODO test cases"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

sb.Reset()
sbPool.Put(sb)
}()
sb.Grow(len(e.errs) * 16)
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 16, in detected (gomnd)

var (
mu sync.Mutex
emu sync.Mutex
errs = make([]error, 0, concurrency*2) // concurrency * recv+send
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
mnd: Magic number: 2, in detected (gomnd)

internal/slices/slices.go Show resolved Hide resolved
@github-actions
Copy link
Contributor

@vdaas-ci
Copy link
Collaborator

Profile Report

typevald-agent-ngtvald-lb-gatewayvald-discoverervald-manager-index
cpu
heap
other images

@kpango kpango merged commit 538fbee into main Apr 20, 2023
@kpango kpango deleted the refactor/errors/improve-errors-join-performance branch April 20, 2023 04:58
@ykadowak ykadowak mentioned this pull request Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants