Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 45b5ed8

Browse files
author
Christoph Hegemann
authored
perf: Find syntactic matches concurrently (#63937)
Closes https://linear.app/sourcegraph/issue/GRAPH-764/filter-syntactic-results-in-parallel Cuts search time for large results in half. A lot more gains when combined with a smarter GitTreeTranslator ## Test plan Covered by existing tests
1 parent 85359ac commit 45b5ed8

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

internal/codeintel/codenav/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ go_library(
4848
"//lib/errors",
4949
"@com_github_dgraph_io_ristretto//:ristretto",
5050
"@com_github_life4_genesis//slices",
51+
"@com_github_sourcegraph_conc//iter",
5152
"@com_github_sourcegraph_go_diff//diff",
5253
"@com_github_sourcegraph_log//:log",
5354
"@com_github_sourcegraph_scip//bindings/go/scip",

internal/codeintel/codenav/syntactic.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"slices"
99

1010
genslices "github.com/life4/genesis/slices"
11+
conciter "github.com/sourcegraph/conc/iter"
1112
"github.com/sourcegraph/log"
1213
"github.com/sourcegraph/scip/bindings/go/scip"
1314
orderedmap "github.com/wk8/go-ordered-map/v2"
@@ -380,19 +381,21 @@ func syntacticUsagesImpl(
380381
}
381382
}
382383

383-
results := [][]SyntacticMatch{}
384-
384+
tasks := make([]orderedmap.Pair[core.RepoRelPath, candidateFile], 0, candidateMatches.Len())
385385
for pair := candidateMatches.Oldest(); pair != nil; pair = pair.Next() {
386-
// We're assuming the upload we found earlier contains the relevant SCIP document
386+
tasks = append(tasks, *pair)
387+
}
388+
results := conciter.Map(tasks, func(pair *orderedmap.Pair[core.RepoRelPath, candidateFile]) []SyntacticMatch {
389+
// We're assuming the index we found earlier contains the relevant SCIP document
387390
// see NOTE(id: single-syntactic-upload)
388-
syntacticMatches, _, err := findSyntacticMatchesForCandidateFile(ctx, trace, mappedIndex, pair.Key, pair.Value)
391+
syntacticMatches, _, err := findSyntacticMatchesForCandidateFile(ctx, trace, mappedIndex, (*pair).Key, (*pair).Value)
389392
if err != nil {
390393
// TODO: Errors that are not "no index found in the DB" should be reported
391394
// TODO: Track metrics about how often this happens (GRAPH-693)
392-
continue
395+
return []SyntacticMatch{}
393396
}
394-
results = append(results, syntacticMatches)
395-
}
397+
return syntacticMatches
398+
})
396399
return SyntacticUsagesResult{Matches: slices.Concat(results...)}, PreviousSyntacticSearch{
397400
MappedIndex: mappedIndex,
398401
SymbolName: symbolName,
@@ -425,14 +428,16 @@ func searchBasedUsagesImpl(
425428
if err != nil {
426429
trace.Warn("Failed to run symbol search, will not mark any search-based usages as definitions", log.Error(err))
427430
}
428-
429-
results := [][]SearchBasedMatch{}
431+
tasks := make([]orderedmap.Pair[core.RepoRelPath, candidateFile], 0, candidateMatches.Len())
430432
for pair := candidateMatches.Oldest(); pair != nil; pair = pair.Next() {
433+
tasks = append(tasks, *pair)
434+
}
435+
436+
results := conciter.Map(tasks, func(pair *orderedmap.Pair[core.RepoRelPath, candidateFile]) []SearchBasedMatch {
431437
if index, ok := syntacticIndex.Get(); ok {
432438
_, searchBasedMatches, err := findSyntacticMatchesForCandidateFile(ctx, trace, index, pair.Key, pair.Value)
433439
if err == nil {
434-
results = append(results, searchBasedMatches)
435-
continue
440+
return searchBasedMatches
436441
} else {
437442
trace.Info("findSyntacticMatches failed, skipping filtering search-based results", log.Error(err))
438443
}
@@ -445,7 +450,7 @@ func searchBasedUsagesImpl(
445450
IsDefinition: candidateSymbols.Contains(pair.Key, rg),
446451
})
447452
}
448-
results = append(results, matches)
449-
}
453+
return matches
454+
})
450455
return slices.Concat(results...), nil
451456
}

0 commit comments

Comments
 (0)