···210210// "start and "end" into "symOffsets". It returns -1 if the new section overlaps
211211// with one of the existing ones.
212212func overlaps(symOffsets []zoekt.DocumentSection, start, end uint32) int {
213213- var i = 0
213213+ i := 0
214214 for i = len(symOffsets) - 1; i >= 0; i-- {
215215 // The most common case is that we exit here, because symOffsets is sorted by
216216 // construction and start is in many cases monotonically increasing.
-1
build/e2e_test.go
···579579 type step struct {
580580 name string
581581 documents []zoekt.Document
582582- branches []zoekt.RepositoryBranch
583582 optFn func(t *testing.T, o *Options)
584583585584 query string
+1-1
cmd/zoekt-mirror-gerrit/main.go
···144144 }
145145146146 for k, v := range *page {
147147- if *active == false || "ACTIVE" == v.State {
147147+ if !*active || "ACTIVE" == v.State {
148148 projects[k] = v
149149 }
150150 skip = skip + 1
+1-1
cmd/zoekt-sourcegraph-indexserver/merge.go
···62626363 // Guard against the user triggering competing merge jobs with the debug
6464 // command.
6565- if !mergeRunning.CAS(false, true) {
6565+ if !mergeRunning.CompareAndSwap(false, true) {
6666 log.Printf("merge already running")
6767 return
6868 }
···1111 "github.com/RoaringBitmap/roaring"
1212)
13131414-// We implement a custom binary marshaller for a list of repos to
1515-// branches. When profiling Sourcegraph this is one of the dominant items.
1616-//
1717-// Wire-format of map[string][]string is pretty straightforward:
1818-//
1919-// byte(1) version
2020-// uvarint(len(map))
2121-// for k, vs in map:
2222-// str(k)
2323-// uvarint(len(vs))
2424-// for v in vs:
2525-// str(v)
2626-//
2727-// where str(v) is uvarint(len(v)) bytes(v)
2828-//
2929-// The above format gives about the same size encoding as gob does. However,
3030-// gob doesn't have a specialization for map[string][]string so we get to
3131-// avoid a lot of intermediate allocations.
3232-//
3333-// The only other specialization we add is treating []string{"HEAD"} as if it
3434-// was []string{}. This is the most common value for branches so avoids the
3535-// need to write it on the wire. This makes us beat gob for encoded size.
3636-//
3737-// The above adds up to a huge improvement, worth the extra complexity:
3838-//
3939-// name old time/op new time/op delta
4040-// RepoBranches_Encode-8 2.37ms ± 3% 0.62ms ± 0% -73.77% (p=0.000 n=10+8)
4141-// RepoBranches_Decode-8 4.19ms ± 2% 0.74ms ± 1% -82.37% (p=0.000 n=10+9)
4242-//
4343-// name old bytes new bytes delta
4444-// RepoBranches_Encode-8 393kB ± 0% 344kB ± 0% -12.48% (p=0.000 n=10+10)
4545-//
4646-// name old alloc/op new alloc/op delta
4747-// RepoBranches_Encode-8 726kB ± 0% 344kB ± 0% -52.60% (p=0.000 n=10+9)
4848-// RepoBranches_Decode-8 2.31MB ± 0% 1.44MB ± 0% -37.51% (p=0.000 n=9+10)
4949-//
5050-// name old allocs/op new allocs/op delta
5151-// RepoBranches_Encode-8 20.0k ± 0% 0.0k ± 0% -100.00% (p=0.000 n=10+10)
5252-// RepoBranches_Decode-8 50.6k ± 0% 0.4k ± 0% -99.26% (p=0.000 n=10+10)
5353-5454-// repoBranchesEncode implements an efficient encoder for RepoBranches.
5555-func repoBranchesEncode(repoBranches map[string][]string) ([]byte, error) {
5656- var b bytes.Buffer
5757- var enc [binary.MaxVarintLen64]byte
5858- varint := func(n int) {
5959- m := binary.PutUvarint(enc[:], uint64(n))
6060- b.Write(enc[:m])
6161- }
6262- str := func(s string) {
6363- varint(len(s))
6464- b.WriteString(s)
6565- }
6666- strSize := func(s string) int {
6767- return binary.PutUvarint(enc[:], uint64(len(s))) + len(s)
6868- }
6969-7070- // Calculate size
7171- size := 1 // version
7272- size += binary.PutUvarint(enc[:], uint64(len(repoBranches)))
7373- for name, branches := range repoBranches {
7474- size += strSize(name) + 1
7575- if l := len(branches); l == 1 && branches[0] == "HEAD" {
7676- continue
7777- } else if l == 0 {
7878- // We reserve "0" for the "HEAD" special case.
7979- return nil, fmt.Errorf("repo with no branches: %q", name)
8080- } else if l > 255 {
8181- // We encode branches len as a byte (saves 11% cpu vs varint). This is
8282- // fine sinze Zoekt can only index upto 64 branches (uses a bitmask on a
8383- // 64bit int to encode branch information for a document)
8484- return nil, fmt.Errorf("can't encode more than 255 branches: %d", l)
8585- }
8686- for _, branch := range branches {
8787- size += strSize(branch)
8888- }
8989- }
9090- b.Grow(size)
9191-9292- // Version
9393- b.WriteByte(1)
9494-9595- // Length
9696- varint(len(repoBranches))
9797-9898- for name, branches := range repoBranches {
9999- str(name)
100100-101101- // Special case "HEAD"
102102- if len(branches) == 1 && branches[0] == "HEAD" {
103103- branches = nil
104104- }
105105-106106- b.WriteByte(byte(len(branches)))
107107- for _, branch := range branches {
108108- str(branch)
109109- }
110110- }
111111-112112- return b.Bytes(), nil
113113-}
114114-115115-// head is the most common slice of branches we search. We re-use it to avoid
116116-// allocations when decoding. We know that zoekt never mutates the
117117-// repoBranches slice, so it is safe to share this slice.
118118-var head = []string{"HEAD"}
119119-12014func branchesReposEncode(brs []BranchRepos) ([]byte, error) {
12115 var b bytes.Buffer
12216 var enc [binary.MaxVarintLen64]byte
-12
shards/shards.go
···10551055 return s, nil
10561056}
1057105710581058-func strSliceEqual(a, b []string) bool {
10591059- if len(a) != len(b) {
10601060- return false
10611061- }
10621062- for i := range a {
10631063- if a[i] != b[i] {
10641064- return false
10651065- }
10661066- }
10671067- return true
10681068-}
10691069-10701058// prioritySlice is a trivial implementation of an array that provides three
10711059// things: appending a value, removing a value, and getting the array's max.
10721060// Operations take O(n) time, which is acceptable because N is restricted to