From babf877fd618dd4c442ca78e920198324527e943 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 18 Aug 2016 01:38:41 +0900 Subject: [PATCH] Increase the number of go routines for search Sort performance increases as the size of each sublist decreases (n in nlog(n) decreases). Merger is then responsible for merging the sorted lists in order, and since in most cases we are only interesed in the matches in the first page on the screen so the overhead in the process is negligible. --- src/matcher.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/matcher.go b/src/matcher.go index d2a7b38..d332b85 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -43,7 +43,7 @@ func NewMatcher(patternBuilder func([]rune) *Pattern, tac: tac, eventBox: eventBox, reqBox: util.NewEventBox(), - partitions: runtime.NumCPU(), + partitions: 16 * runtime.NumCPU(), mergerCache: make(map[string]*Merger)} } @@ -106,18 +106,19 @@ func (m *Matcher) Loop() { } func (m *Matcher) sliceChunks(chunks []*Chunk) [][]*Chunk { - perSlice := len(chunks) / m.partitions + partitions := m.partitions + perSlice := len(chunks) / partitions - // No need to parallelize if perSlice == 0 { - return [][]*Chunk{chunks} + partitions = len(chunks) + perSlice = 1 } - slices := make([][]*Chunk, m.partitions) - for i := 0; i < m.partitions; i++ { + slices := make([][]*Chunk, partitions) + for i := 0; i < partitions; i++ { start := i * perSlice end := start + perSlice - if i == m.partitions-1 { + if i == partitions-1 { end = len(chunks) } slices[i] = chunks[start:end]