Skip to content

Commit 2ef86ed

Browse files
committed
feat(perf): benchmarks + expand cartographer FindFiles/SearchContent API
- Add perf_bench_test.go: 22 benchmarks covering recordCommit O(n²), co-change pipeline simulation, importCouldReferTo, shouldIgnore - Add structural_bench_test.go (CGO): 11 benchmarks for call-site annotation pipeline with documented baselines - Expand FindFiles to accept FindOptions (filter by mtime, size, depth) - Expand SearchContentOptions with full ripgrep-parity fields - Add FileCount, FilesWithMatches/WithoutMatch fields to SearchResult
1 parent f0f1214 commit 2ef86ed

5 files changed

Lines changed: 573 additions & 14 deletions

File tree

internal/cartographer/bridge.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,26 @@ func SearchContent(path, pattern string, opts *SearchContentOptions) (*SearchRes
355355
}
356356

357357
// FindFiles finds files whose repo-relative path matches a glob pattern.
358-
// limit=0 means unlimited.
359-
func FindFiles(path, pattern string, limit uint32) (*FindResult, error) {
358+
// limit=0 means unlimited. opts may be nil to use defaults.
359+
func FindFiles(path, pattern string, limit uint32, opts *FindOptions) (*FindResult, error) {
360360
cPath := C.CString(path)
361361
defer C.free(unsafe.Pointer(cPath))
362362

363363
cPattern := C.CString(pattern)
364364
defer C.free(unsafe.Pointer(cPattern))
365365

366+
var cOpts *C.char
367+
if opts != nil {
368+
b, err := json.Marshal(opts)
369+
if err != nil {
370+
return nil, &CartographerError{err.Error()}
371+
}
372+
cOpts = C.CString(string(b))
373+
defer C.free(unsafe.Pointer(cOpts))
374+
}
375+
366376
resp, err := callFFI(func() *C.char {
367-
return C.cartographer_find_files(cPath, cPattern, C.uint(limit))
377+
return C.cartographer_find_files(cPath, cPattern, C.uint(limit), cOpts)
368378
})
369379
if err != nil {
370380
return nil, err

internal/cartographer/bridge_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ func Semidiff(_, _, _ string) ([]SemidiffFile, error)
2727
func RankedSkeleton(_ string, _ []string, _ uint32) (*RankedSkeletonResult, error) { return nil, ErrUnavailable }
2828
func UnreferencedSymbols(_ string) (*UnreferencedSymbolsResult, error) { return nil, ErrUnavailable }
2929
func SearchContent(_, _ string, _ *SearchContentOptions) (*SearchResult, error) { return nil, ErrUnavailable }
30-
func FindFiles(_, _ string, _ uint32) (*FindResult, error) { return nil, ErrUnavailable }
30+
func FindFiles(_, _ string, _ uint32, _ *FindOptions) (*FindResult, error) { return nil, ErrUnavailable }

internal/cartographer/types.go

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,35 @@ type SemidiffFile struct {
178178
Removed []string `json:"removed"`
179179
}
180180

181-
// SearchContentOptions configures a content search request.
181+
// SearchContentOptions configures a content search request (mirrors Rust SearchOptions).
182182
type SearchContentOptions struct {
183-
Literal bool `json:"literal,omitempty"`
184-
CaseSensitive *bool `json:"caseSensitive,omitempty"` // default true
185-
ContextLines int `json:"contextLines,omitempty"`
186-
MaxResults int `json:"maxResults,omitempty"`
187-
FileGlob string `json:"fileGlob,omitempty"`
183+
Literal bool `json:"literal,omitempty"`
184+
CaseSensitive *bool `json:"caseSensitive,omitempty"` // default true
185+
ContextLines int `json:"contextLines,omitempty"`
186+
BeforeContext int `json:"beforeContext,omitempty"`
187+
AfterContext int `json:"afterContext,omitempty"`
188+
MaxResults int `json:"maxResults,omitempty"`
189+
FileGlob string `json:"fileGlob,omitempty"`
190+
ExcludeGlob string `json:"excludeGlob,omitempty"`
191+
ExtraPatterns []string `json:"extraPatterns,omitempty"`
192+
InvertMatch bool `json:"invertMatch,omitempty"`
193+
WordRegexp bool `json:"wordRegexp,omitempty"`
194+
OnlyMatching bool `json:"onlyMatching,omitempty"`
195+
FilesWithMatches bool `json:"filesWithMatches,omitempty"`
196+
FilesWithoutMatch bool `json:"filesWithoutMatch,omitempty"`
197+
CountOnly bool `json:"countOnly,omitempty"`
198+
NoIgnore bool `json:"noIgnore,omitempty"`
199+
SearchPath string `json:"searchPath,omitempty"`
200+
}
201+
202+
// FindOptions configures a file-find request (mirrors Rust FindOptions).
203+
type FindOptions struct {
204+
ModifiedSinceSecs *uint64 `json:"modifiedSinceSecs,omitempty"`
205+
NewerThan string `json:"newerThan,omitempty"`
206+
MinSizeBytes *uint64 `json:"minSizeBytes,omitempty"`
207+
MaxSizeBytes *uint64 `json:"maxSizeBytes,omitempty"`
208+
MaxDepth *int `json:"maxDepth,omitempty"`
209+
NoIgnore bool `json:"noIgnore,omitempty"`
188210
}
189211

190212
// ContextLine is one line of before/after context around a search match.
@@ -198,23 +220,34 @@ type ContentMatch struct {
198220
Path string `json:"path"`
199221
LineNumber int `json:"lineNumber"`
200222
Line string `json:"line"`
223+
MatchedTexts []string `json:"matchedTexts,omitempty"`
201224
BeforeContext []ContextLine `json:"beforeContext,omitempty"`
202225
AfterContext []ContextLine `json:"afterContext,omitempty"`
203226
}
204227

228+
// FileCount holds the match count for one file (count_only mode).
229+
type FileCount struct {
230+
Path string `json:"path"`
231+
Count int `json:"count"`
232+
}
233+
205234
// SearchResult is returned by SearchContent.
206235
type SearchResult struct {
207-
Matches []ContentMatch `json:"matches"`
208-
TotalMatches int `json:"totalMatches"`
209-
FilesSearched int `json:"filesSearched"`
210-
Truncated bool `json:"truncated"`
236+
Matches []ContentMatch `json:"matches"`
237+
TotalMatches int `json:"totalMatches"`
238+
FilesSearched int `json:"filesSearched"`
239+
Truncated bool `json:"truncated"`
240+
FilesWithMatches []string `json:"filesWithMatches,omitempty"`
241+
FilesWithoutMatch []string `json:"filesWithoutMatch,omitempty"`
242+
FileCounts []FileCount `json:"fileCounts,omitempty"`
211243
}
212244

213245
// FindFile is one file returned by FindFiles.
214246
type FindFile struct {
215247
Path string `json:"path"`
216248
Language *string `json:"language,omitempty"`
217249
SizeBytes uint64 `json:"sizeBytes"`
250+
Modified *string `json:"modified,omitempty"`
218251
}
219252

220253
// FindResult is returned by FindFiles.

0 commit comments

Comments
 (0)