optimize term vectors/locations via preallocated arrays
The change should hit the allocator less often when processing term vectors/locations as it preallocates larger, contiguous arrays of records upfront.
This commit is contained in:
parent
8b140d84c4
commit
c2bafa2a51
|
@ -745,18 +745,19 @@ func (udc *UpsideDownCouch) termFieldVectorsFromTermVectors(in []*TermVector) []
|
|||
return nil
|
||||
}
|
||||
|
||||
a := make([]index.TermFieldVector, len(in))
|
||||
rv := make([]*index.TermFieldVector, len(in))
|
||||
|
||||
for i, tv := range in {
|
||||
fieldName := udc.fieldCache.FieldIndexed(tv.field)
|
||||
tfv := index.TermFieldVector{
|
||||
a[i] = index.TermFieldVector{
|
||||
Field: fieldName,
|
||||
ArrayPositions: tv.arrayPositions,
|
||||
Pos: tv.pos,
|
||||
Start: tv.start,
|
||||
End: tv.end,
|
||||
}
|
||||
rv[i] = &tfv
|
||||
rv[i] = &a[i]
|
||||
}
|
||||
return rv
|
||||
}
|
||||
|
|
|
@ -141,39 +141,41 @@ func (s *TermQueryScorer) Score(ctx *search.SearchContext, termMatch *index.Term
|
|||
}
|
||||
|
||||
if termMatch.Vectors != nil && len(termMatch.Vectors) > 0 {
|
||||
locs := make([]search.Location, len(termMatch.Vectors))
|
||||
locsUsed := 0
|
||||
|
||||
totalPositions := 0
|
||||
for _, v := range termMatch.Vectors {
|
||||
totalPositions += len(v.ArrayPositions)
|
||||
}
|
||||
positions := make([]float64, totalPositions)
|
||||
positionsUsed := 0
|
||||
|
||||
rv.Locations = make(search.FieldTermLocationMap)
|
||||
for _, v := range termMatch.Vectors {
|
||||
tlm := rv.Locations[v.Field]
|
||||
if tlm == nil {
|
||||
tlm = make(search.TermLocationMap)
|
||||
rv.Locations[v.Field] = tlm
|
||||
}
|
||||
|
||||
loc := search.Location{
|
||||
Pos: float64(v.Pos),
|
||||
Start: float64(v.Start),
|
||||
End: float64(v.End),
|
||||
}
|
||||
loc := &locs[locsUsed]
|
||||
locsUsed++
|
||||
|
||||
loc.Pos = float64(v.Pos)
|
||||
loc.Start = float64(v.Start)
|
||||
loc.End = float64(v.End)
|
||||
|
||||
if len(v.ArrayPositions) > 0 {
|
||||
loc.ArrayPositions = make([]float64, len(v.ArrayPositions))
|
||||
loc.ArrayPositions = positions[positionsUsed:positionsUsed+len(v.ArrayPositions)]
|
||||
for i, ap := range v.ArrayPositions {
|
||||
loc.ArrayPositions[i] = float64(ap)
|
||||
}
|
||||
positionsUsed += len(v.ArrayPositions)
|
||||
}
|
||||
|
||||
locations := tlm[s.queryTerm]
|
||||
if locations == nil {
|
||||
locations = make(search.Locations, 1)
|
||||
locations[0] = &loc
|
||||
} else {
|
||||
locations = append(locations, &loc)
|
||||
}
|
||||
tlm[s.queryTerm] = locations
|
||||
|
||||
rv.Locations[v.Field] = tlm
|
||||
tlm[s.queryTerm] = append(tlm[s.queryTerm], loc)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rv
|
||||
|
|
Loading…
Reference in New Issue