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

internal: Improve the Iter performance of LockMap on empty maps #2127

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

ajgajg1134
Copy link
Contributor

What does this PR do?

Improves LockMap.Iter performance for empty maps

goos: darwin
goarch: arm64
pkg: gopkg.in/DataDog/dd-trace-go.v1/internal
                 │ original.out │          withAtomic2.out           │
                 │    sec/op    │   sec/op     vs base               │
Iter/original-10   14.280n ± 1%   1.998n ± 0%  -86.00% (p=0.002 n=6)

                 │ original.out │        withAtomic2.out        │
                 │     B/op     │    B/op     vs base           │
Iter/original-10     0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=6) ¹
¹ all samples are equal

                 │ original.out │        withAtomic2.out        │
                 │  allocs/op   │ allocs/op   vs base           │
Iter/original-10     0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=6) ¹
¹ all samples are equal

Motivation

Turns out doing RLock and RUnlock can still be slow especially when this code is in a HOT path. For most users this map will be empty. Therefore it's worth speeding up that case at the cost of a tiny bit of extra memory and a bit of complexity.

Describe how to test/QA your changes

Added a thrash test that when run with the race detector should help make sure we don't miss anything (and it verifies that the count and len match at the end to make sure they don't get out of sync).

Reviewer's Checklist

  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

Sorry, something went wrong.

@ajgajg1134 ajgajg1134 marked this pull request as ready for review July 19, 2023 15:54
@ajgajg1134 ajgajg1134 requested a review from a team as a code owner July 19, 2023 15:54
@pr-commenter
Copy link

pr-commenter bot commented Jul 19, 2023

Benchmarks

Benchmark execution time: 2023-07-19 15:59:01

Comparing candidate commit 5b7943f in PR branch andrew.glaude/FasterLockMap with baseline commit f905f70 in branch release-v1.53.x.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 0 unstable metrics.

@ajgajg1134 ajgajg1134 merged commit 3eabc50 into release-v1.53.x Jul 19, 2023
@ajgajg1134 ajgajg1134 deleted the andrew.glaude/FasterLockMap branch July 19, 2023 19:44
ajgajg1134 added a commit that referenced this pull request Jul 19, 2023
Turns out doing RLock and RUnlock can still be slow especially when this code is in a HOT path. For most users this map will be empty. Therefore it's worth speeding up that case at the cost of a tiny bit of extra memory and a bit of complexity.
knusbaum pushed a commit that referenced this pull request Jul 20, 2023
Turns out doing RLock and RUnlock can still be slow especially when this code is in a HOT path. For most users this map will be empty. Therefore it's worth speeding up that case at the cost of a tiny bit of extra memory and a bit of complexity.

Cherry-picks across #2127
katiehockman pushed a commit that referenced this pull request Jul 26, 2023
Turns out doing RLock and RUnlock can still be slow especially when this code is in a HOT path. For most users this map will be empty. Therefore it's worth speeding up that case at the cost of a tiny bit of extra memory and a bit of complexity.

Cherry-picks across #2127
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.

None yet

2 participants