From aae2e7bd3bdfbb7796e26786bfa3db769349d6df Mon Sep 17 00:00:00 2001 From: Injun Song Date: Tue, 20 Jul 2021 16:35:35 +0900 Subject: [PATCH] sn: remove unnecessary sort in committer (#472) 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 https://github.com/golang/go/issues/17332. Resolves [#VARLOG-530](VARLOG-530). --- internal/storagenode/executor/committer.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/storagenode/executor/committer.go b/internal/storagenode/executor/committer.go index 3df4d2fe0..87edbe476 100644 --- a/internal/storagenode/executor/committer.go +++ b/internal/storagenode/executor/committer.go @@ -4,7 +4,6 @@ package executor import ( "context" - "sort" "sync" "sync/atomic" "time" @@ -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()