Skip to content

Commit

Permalink
Use Intersect to Narrow Iterate Range and Reduce Memory Allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Li committed Jan 10, 2025
1 parent 25a8814 commit a5576a1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,10 @@ func (l *List) Uids(opt ListOptions) (*pb.List, error) {
return out, nil
}

preAllowcateLength := x.MinInt(opt.First, l.mutationMap.len()+codec.ApproxLen(l.plist.Pack))
if opt.Intersect != nil {
preAllowcateLength = x.MinInt(preAllowcateLength, len(opt.Intersect.Uids))

Check failure on line 1690 in posting/list.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to preAllowcateLength (ineffassign)
}
// Pre-assign length to make it faster.
res := make([]uint64, 0, x.MinInt(opt.First, len(opt.Intersect.Uids), l.mutationMap.len()+codec.ApproxLen(l.plist.Pack)))

Check failure on line 1693 in posting/list.go

View workflow job for this annotation

GitHub Actions / lint

The line is 122 characters long, which exceeds the maximum of 120 characters. (lll)

Expand Down

0 comments on commit a5576a1

Please sign in to comment.