Skip to content

Commit

Permalink
sn: remove unnecessary sort in committer (#472)
Browse files Browse the repository at this point in the history
This patch removes unnecessary sort in committer since the number of
elements in the sorted container is one mostly. In addition, the
argument of `sort.Slice` escapes to the heap. See
golang/go#17332.

Resolves [#VARLOG-530](VARLOG-530).
  • Loading branch information
ijsong authored and GitHub Enterprise committed Jul 20, 2021
1 parent a3cc86d commit bed15f2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/storagenode/executor/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package executor

import (
"context"
"sort"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -269,9 +268,15 @@ func (c *committerImpl) commit(ctx context.Context) error {
// - What is the proper batch size?
// - Maybe incoming commit messages are already sorted or partially sorted, is it helpful
// sorting again here?
sort.Slice(c.commitTaskBatch, func(i, j int) bool {
return c.commitTaskBatch[i].highWatermark < c.commitTaskBatch[j].highWatermark
})

// Sort is skipped.
// - There are a few commit tasks in a batch.
// - Escape problem: https://github.com/golang/go/issues/17332
/*
sort.Slice(c.commitTaskBatch, func(i, j int) bool {
return c.commitTaskBatch[i].highWatermark < c.commitTaskBatch[j].highWatermark
})
*/

for _, ct := range c.commitTaskBatch {
globalHighWatermark, _ := c.lsc.reportCommitBase()
Expand Down

0 comments on commit bed15f2

Please sign in to comment.