-
Notifications
You must be signed in to change notification settings - Fork 1.5k
spanner: large number of unnecessary allocations constructing mutations in BatchWrite #12680
Copy link
Copy link
Closed
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.triage meI really want to be triaged.I really want to be triaged.
Description
Client
Spanner
Environment
All, on latest master
Code and Dependencies
In spanner/mutation.go, mutationsProto unnecessary allocates slices and rand objects:
func mutationsProto(ms []*Mutation) ([]*sppb.Mutation, *sppb.Mutation, error) {
var selectedMutation *Mutation
var nonInsertMutations []*Mutation
...
if len(nonInsertMutations) > 0 {
selectedMutation = nonInsertMutations[rand.New(rand.NewSource(time.Now().UnixNano())).Intn(len(nonInsertMutations))]
}
...
}All production callers of this function ignore the second return value. The only functionality of tracking selectedMutation, nonInsertMutations seem to be for test.
Expected behavior
There are fewer unnecessary allocations.
Actual behavior
Allocations due to rand and slices only used for test cause massive amounts of allocations, increasing CPU and memory usage. See screenshot for a heap profile taken on a pod that performs a large number of BatchWrite calls.
Screenshots
Heap profile viewing "alloc - space" showing large amounts of allocated space:

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the Spanner API.Issues related to the Spanner API.triage meI really want to be triaged.I really want to be triaged.