diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2016-09-07 09:58:18 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-09-18 14:34:46 +0900 |
commit | 2fc7c18747250ebf8adf68d2057ec22af6976f29 (patch) | |
tree | aab013c4492a82dd613866a35b98fc9de42f533d /src/matcher.go | |
parent | 8ef2420677abf5cca27b47bead6e70e42220c7aa (diff) |
Revise ranking algorithm
Diffstat (limited to 'src/matcher.go')
-rw-r--r-- | src/matcher.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/matcher.go b/src/matcher.go index 9814ba9b..57c263ab 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -26,6 +26,7 @@ type Matcher struct { eventBox *util.EventBox reqBox *util.EventBox partitions int + slab []*util.Slab mergerCache map[string]*Merger } @@ -37,13 +38,15 @@ const ( // NewMatcher returns a new Matcher func NewMatcher(patternBuilder func([]rune) *Pattern, sort bool, tac bool, eventBox *util.EventBox) *Matcher { + partitions := util.Min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions) return &Matcher{ patternBuilder: patternBuilder, sort: sort, tac: tac, eventBox: eventBox, reqBox: util.NewEventBox(), - partitions: util.Min(8*runtime.NumCPU(), 32), + partitions: partitions, + slab: make([]*util.Slab, partitions), mergerCache: make(map[string]*Merger)} } @@ -153,12 +156,15 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { for idx, chunks := range slices { waitGroup.Add(1) - go func(idx int, chunks []*Chunk) { + if m.slab[idx] == nil { + m.slab[idx] = util.MakeSlab(slab16Size, slab32Size) + } + go func(idx int, slab *util.Slab, chunks []*Chunk) { defer func() { waitGroup.Done() }() count := 0 allMatches := make([][]*Result, len(chunks)) for idx, chunk := range chunks { - matches := request.pattern.Match(chunk) + matches := request.pattern.Match(chunk, slab) allMatches[idx] = matches count += len(matches) if cancelled.Get() { @@ -178,7 +184,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) { } } resultChan <- partialResult{idx, sliceMatches} - }(idx, chunks) + }(idx, m.slab[idx], chunks) } wait := func() bool { |