Skip to content

Commit

Permalink
replica_rac2: prevent unnecessary heap allocation of admitted vector
Browse files Browse the repository at this point in the history
Informs cockroachdb#128033

Epic: CRDB-37515

Release note: None
  • Loading branch information
sumeerbhola committed Oct 7, 2024
1 parent 0ce3817 commit db1c16f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/kv/kvserver/kvflowcontrol/replica_rac2/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,12 @@ func (p *processorImpl) maybeSendAdmittedRaftMuLocked(ctx context.Context) {
if p.leaderNodeID == 0 {
return
}
// NB: just using av.Admitted[:] in kvflowcontrolpb.AdmittedState below
// causes av.Admitted to escape to the heap when initially returned from the
// admitted() call, which doesn't account for the early returns that can be
// common. So we explicitly allocate here.
admitted := make([]uint64, raftpb.NumPriorities)
copy(admitted, av.Admitted[:])
// Piggyback the new admitted vector to the message stream going to the node
// containing the leader replica.
p.opts.AdmittedPiggybacker.Add(p.leaderNodeID, kvflowcontrolpb.PiggybackedAdmittedState{
Expand All @@ -819,7 +825,7 @@ func (p *processorImpl) maybeSendAdmittedRaftMuLocked(ctx context.Context) {
ToReplicaID: p.leaderID,
Admitted: kvflowcontrolpb.AdmittedState{
Term: av.Term,
Admitted: av.Admitted[:],
Admitted: admitted,
}})
}

Expand Down

0 comments on commit db1c16f

Please sign in to comment.