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.
This commit is contained in:
Junegunn Choi 2016-08-18 01:38:41 +09:00
parent 935272824e
commit babf877fd6
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -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]