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

kv: combine heap allocations in maybeStripInFlightWrites #74358

Merged

Conversation

nvanbenschoten
Copy link
Member

This commit combines two of the heap allocations incurred by 1PC calls
to maybeStripInFlightWrites when making a shallow copy of the provided
BatchRequest into a single allocation.

In a write-heavy workload, these were observed to account for about 0.8% of
all heap allocations, meaning that this change should reduce heap allocations in
that workload by about 0.4%.

      File: cockroach
Type: alloc_objects
Time: Dec 31, 2021 at 3:51am (UTC)
Active filters:
   focus=maybeStripInFlightWrites
Showing nodes accounting for 2259283, 1.37% of 164666499 total
----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context
----------------------------------------------------------+-------------
...
----------------------------------------------------------+-------------
                                            506152   100% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.(*Replica).sendWithRangeID /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_send.go:140
         0     0%  0.63%     506152  0.31%                | github.com/cockroachdb/cockroach/pkg/kv/kvserver.maybeStripInFlightWrites /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_batch_updates.go:58
                                            506152   100% |   github.com/cockroachdb/cockroach/pkg/roachpb.(*EndTxnRequest).ShallowCopy /go/src/github.com/cockroachdb/cockroach/pkg/roachpb/api.go:797 (inline)
----------------------------------------------------------+-------------
                                            720901   100% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.(*Replica).sendWithRangeID /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_send.go:140
         0     0%  0.63%     720901  0.44%                | github.com/cockroachdb/cockroach/pkg/kv/kvserver.maybeStripInFlightWrites /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_batch_updates.go:62
                                            720901   100% |   github.com/cockroachdb/cockroach/pkg/roachpb.(*RequestUnion).MustSetInner /go/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated.go:385
----------------------------------------------------------+-------------

This commit combines two of the heap allocations incurred by 1PC calls
to `maybeStripInFlightWrites` when making a shallow copy of the provided
`BatchRequest` into a single allocation.

In a write-heavy workload, these were observed to account for about **0.8%** of
all heap allocations, meaning that this change should reduce heap allocations in
that workload by about **0.4%**.

```
      File: cockroach
Type: alloc_objects
Time: Dec 31, 2021 at 3:51am (UTC)
Active filters:
   focus=maybeStripInFlightWrites
Showing nodes accounting for 2259283, 1.37% of 164666499 total
----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context
----------------------------------------------------------+-------------
...
----------------------------------------------------------+-------------
                                            506152   100% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.(*Replica).sendWithRangeID /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_send.go:140
         0     0%  0.63%     506152  0.31%                | github.com/cockroachdb/cockroach/pkg/kv/kvserver.maybeStripInFlightWrites /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_batch_updates.go:58
                                            506152   100% |   github.com/cockroachdb/cockroach/pkg/roachpb.(*EndTxnRequest).ShallowCopy /go/src/github.com/cockroachdb/cockroach/pkg/roachpb/api.go:797 (inline)
----------------------------------------------------------+-------------
                                            720901   100% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.(*Replica).sendWithRangeID /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_send.go:140
         0     0%  0.63%     720901  0.44%                | github.com/cockroachdb/cockroach/pkg/kv/kvserver.maybeStripInFlightWrites /go/src/github.com/cockroachdb/cockroach/pkg/kv/kvserver/replica_batch_updates.go:62
                                            720901   100% |   github.com/cockroachdb/cockroach/pkg/roachpb.(*RequestUnion).MustSetInner /go/src/github.com/cockroachdb/cockroach/pkg/roachpb/batch_generated.go:385
----------------------------------------------------------+-------------
```
@nvanbenschoten nvanbenschoten requested a review from a team as a code owner December 31, 2021 04:12
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@tbg tbg left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei)

@nvanbenschoten
Copy link
Member Author

TFTR!

bors r=tbg

@craig
Copy link
Contributor

craig bot commented Jan 3, 2022

Build succeeded:

@craig craig bot merged commit 5669b9d into cockroachdb:master Jan 3, 2022
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/assortedPerf19 branch January 6, 2022 16:45
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.

3 participants