From e8b304506231a8c8352ab1dd4bdeed458efb89c5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 22 Feb 2024 20:44:11 +0200 Subject: [PATCH] lib/storage: handle common case when the number of rows passed to flushRowsToInmemoryParts() doesnt exceed maxRawRowsPerShard --- lib/storage/partition.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/storage/partition.go b/lib/storage/partition.go index de8295370..96b4c25dc 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -506,8 +506,17 @@ func (pt *partition) flushRowsToInmemoryParts(rows []rawRow) { return } - // Merge rows into in-memory parts. maxRows := maxRawRowsPerShard + if len(rows) <= maxRows { + // Common case - convert rows to a single in-memory part + pw := pt.createInmemoryPart(rows) + if pw != nil { + pt.addToInmemoryParts(pw) + } + return + } + + // Merge rows into in-memory parts. var pwsLock sync.Mutex pws := make([]*partWrapper, 0, (len(rows)+maxRows-1)/maxRows) wg := getWaitGroup()