summaryrefslogtreecommitdiffstats
path: root/src/matcher.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-08-18 01:38:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-08-18 01:46:05 +0900
commitbabf877fd618dd4c442ca78e920198324527e943 (patch)
tree2f166936609521f57dfcddce6454bb38fb72c0a7 /src/matcher.go
parent935272824ebb7ec6de3cd981caf71c8b5208f9b3 (diff)
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.
Diffstat (limited to 'src/matcher.go')
-rw-r--r--src/matcher.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/matcher.go b/src/matcher.go
index d2a7b389..d332b85b 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]