Skip to content

index: reuse resolved lines for chunk matches - #1202

Merged
keegancsmith merged 2 commits into
sourcegraph:mainfrom
perfloop-oss:perfloop-pr-open-hnpnhx3amt
Oct 29, 2026
Merged

keegancsmith merged 2 commits into
sourcegraph:mainfrom
perfloop-oss:perfloop-pr-open-hnpnhx3amt

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

Chunk-mode Search used to resolve content matches to lines while grouping candidates, building ranges, and scoring chunks. This change carries each resolved range through those steps so the call avoids repeated line lookups.

A monotone cursor reuses the current line and binary-searches from there after a gap. The emitted ranges supply start lines to scoring, and chunks use contiguous spans of the original candidates. The existing end-line clamp, unsorted-candidate fallback, UTF-8 columns, score ties, debug scores, BestLineMatch, and symbol associations are preserved. No public API or shard format changes.

The index package tests, focused scoring and ranking end-to-end tests, and all-package Go build passed. The full repository test suite remains for target CI.

Workload Measure Metric Before median After median Paired change Outcome / requirement Paired runs
dense source-file chunk Search time ns/op 33.05 µs 25.9 µs -20.2% improvement passed 9
sparse end-of-file chunk Search time ns/op 5.826 µs 5.689 µs −1.8% non-regression passed; lower is better; required population loss ≤ 0.05 × |baseline median| ns 11
wide-context chunk Search time ns/op 30.09 µs 23.56 µs −22.1% non-regression passed; lower is better; required population loss ≤ 0.05 × |baseline median| ns 12
existing synthetic chunk Search benchmark time ns/op 6.185 ms 5.28 ms −14.3% non-regression passed; lower is better; required population loss ≤ 0.05 × |baseline median| ns 13

The source-file measurements time repeated Searcher.Search calls with ChunkMatches enabled on a one-document shard built from checked-in Go files; shard construction and initial validation are outside the timer, and the same harness and source bytes are used on both versions. Dense input is the case-sensitive literal func in search/shards.go (85 matches across 1,679 newline offsets); the sparse guard is the single return &cur near EOF in query/parse.go (652 newline offsets). The context guard uses eight context lines. The existing synthetic BenchmarkScoreChunkMatches in index/index_test.go is also included as a guard, not as the consumer estimate. The auxiliary Go benchmark harness used for these measurements is not included in the PR. ns/op is elapsed time per Search call, not CPU time. Production traffic mix, input prevalence, and deployment-level savings remain unmeasured.


Generated by Perfloop. Human sponsor: Tomás Senart.

Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Tomás Senart <[email protected]>
Signed-off-by: Perfloop Agent <[email protected]>
Signed-off-by: Tomás Senart <[email protected]>
@tsenart

tsenart commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Hi @keegancsmith :)

@keegancsmith
keegancsmith self-requested a review October 29, 2026 15:36
@keegancsmith

Copy link
Copy Markdown
Member

Maintainers are allowed to edit this pull request.

GitHub isn't letting me push. I'll just land and fast follow with some minor changes.

@keegancsmith

Copy link
Copy Markdown
Member

@tsenart 👋

@keegancsmith keegancsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@keegancsmith
keegancsmith merged commit 38d9078 into sourcegraph:main Oct 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants