Skip to content

Conversation

@yuzefovich
Copy link
Member

In the txn write buffer we need to merge the ScanResponse coming from the server with any overlapping writes that we've buffered. This requires us to allocate respMerger.batchResponses which is the "staging" area of the merged response. However, if we don't have any overlapping buffered writes, then we simply copy the server response into that staging area. This commit adds an optimization to avoid this extra copy in a special but common case when the buffer is empty (i.e. we're in a read-only txn). We could extend the optimization further but that is left as a TODO.

Epic: None
Release note: None

@blathers-crl
Copy link

blathers-crl bot commented Dec 10, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@yuzefovich
Copy link
Member Author

name                                                                     old time/op    new time/op    delta
ScanFilter/SharedProcessTenantCockroach/count1=25/count2=400/limit=50-8    1.71ms ± 2%    1.54ms ± 2%   -9.67%  (p=0.000 n=9+9)

name                                                                     old alloc/op   new alloc/op   delta
ScanFilter/SharedProcessTenantCockroach/count1=25/count2=400/limit=50-8     509kB ± 1%     329kB ± 2%  -35.24%  (p=0.000 n=9+9)

name                                                                     old allocs/op  new allocs/op  delta
ScanFilter/SharedProcessTenantCockroach/count1=25/count2=400/limit=50-8       912 ± 7%       748 ± 7%  -17.98%  (p=0.000 n=10+10)

@yuzefovich yuzefovich marked this pull request as ready for review December 10, 2025 02:10
@yuzefovich yuzefovich requested a review from a team as a code owner December 10, 2025 02:10
In the txn write buffer we need to merge the ScanResponse coming from
the server with any overlapping writes that we've buffered. This
requires us to allocate `respMerger.batchResponses` which is the
"staging" area of the merged response. However, if we don't have any
overlapping buffered writes, then we simply copy the server response
into that staging area. This commit adds an optimization to avoid this
extra copy in a special but common case when the buffer is empty (i.e.
we're in a read-only txn). We could extend the optimization further but
that is left as a TODO.

Release note: None
Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Thanks for digging into this one. This seems like a pretty clear win.

@yuzefovich
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Dec 10, 2025

@craig craig bot merged commit 1645953 into cockroachdb:master Dec 10, 2025
24 checks passed
@yuzefovich yuzefovich deleted the bw-optimize branch December 10, 2025 18:06
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.

3 participants