Skip to content

Commit

Permalink
sql/row: reduce allocations in newTxnKVFetcher
Browse files Browse the repository at this point in the history
Two heap-allocated integers are now allocated together in a two-field
struct.

Release note: None
  • Loading branch information
mgartner committed Dec 16, 2024
1 parent 8dcc198 commit e75daae
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/sql/row/kv_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ func newTxnKVFetcher(
forceProductionKVBatchSize bool,
ext *fetchpb.IndexFetchSpec_ExternalRowData,
) *txnKVFetcher {
alloc := new(struct {
batchRequestsIssued int64
kvPairsRead int64
})
var sendFn sendFunc
var batchRequestsIssued int64
if bsHeader == nil {
sendFn = makeSendFunc(txn, ext, &batchRequestsIssued)
sendFn = makeSendFunc(txn, ext, &alloc.batchRequestsIssued)
} else {
negotiated := false
sendFn = func(ctx context.Context, ba *kvpb.BatchRequest) (br *kvpb.BatchResponse, _ error) {
Expand All @@ -91,7 +94,7 @@ func newTxnKVFetcher(
if pErr != nil {
return nil, pErr.GoError()
}
batchRequestsIssued++
alloc.batchRequestsIssued++
return br, nil
}
}
Expand All @@ -107,8 +110,8 @@ func newTxnKVFetcher(
deadlockTimeout: deadlockTimeout,
acc: acc,
forceProductionKVBatchSize: forceProductionKVBatchSize,
kvPairsRead: new(int64),
batchRequestsIssued: &batchRequestsIssued,
kvPairsRead: &alloc.kvPairsRead,
batchRequestsIssued: &alloc.batchRequestsIssued,
}
fetcherArgs.admission.requestHeader = txn.AdmissionHeader()
fetcherArgs.admission.responseQ = txn.DB().SQLKVResponseAdmissionQ
Expand Down

0 comments on commit e75daae

Please sign in to comment.