Skip to content

kv: combine heap allocations in maybeStripInFlightWrites#74358

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/assortedPerf19
Jan 3, 2022
Merged

kv: combine heap allocations in maybeStripInFlightWrites#74358
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/assortedPerf19

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Dec 31, 2021

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
----------------------------------------------------------+-------------
```
@nvb nvb requested a review from andreimatei December 31, 2021 04:12
@nvb nvb requested a review from a team as a code owner December 31, 2021 04:12
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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)

@nvb
Copy link
Copy Markdown
Contributor Author

nvb commented Jan 3, 2022

TFTR!

bors r=tbg

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 3, 2022

Build succeeded:

@craig craig bot merged commit 5669b9d into cockroachdb:master Jan 3, 2022
@nvb nvb 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