⚡ Optimize incremental indexing array lookup to Map#85
Conversation
Co-authored-by: mbayue <70324722+mbayue@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant Pipeline as Incremental Indexing Pipeline
participant SourceFiles as sourceFiles[]
participant PrevItems as prevItems[]
participant PrevItemsMap as NEW: prevItemsMap (Map)
participant ModifiedOrAdded as modifiedOrAdded[]
Note over Pipeline,ModifiedOrAdded: Optimized Change Detection Flow
Pipeline->>PrevItems: Process previous index items
PrevItems->>PrevItemsMap: Build Map keyed by path
Note over PrevItemsMap: O(N) one-time build
Pipeline->>SourceFiles: Iterate through current source files
loop For each source file
SourceFiles->>PrevItemsMap: Get by path
alt Item exists in Map
PrevItemsMap-->>Pipeline: prevItem (or undefined)
Pipeline->>Pipeline: Compare SHA values
alt SHA changed
Pipeline->>ModifiedOrAdded: Add to result
else SHA unchanged
Pipeline->>Pipeline: Skip (no change)
end
else Item not in Map (new file)
PrevItemsMap-->>Pipeline: undefined
Pipeline->>ModifiedOrAdded: Add to result
end
end
Pipeline-->>SourceFiles: Return modifiedOrAdded[]
Note over Pipeline,ModifiedOrAdded: O(1) lookup per file (was O(M))
💡 What:
Optimized the incremental indexing array lookup in
server/search/indexing-pipeline.tsby converting the inner O(M)Array.prototype.find()search insideArray.prototype.filter()into an O(1)Map.prototype.get()lookup.🎯 Why:
The previous implementation filtered
sourceFilesand inside the filter callback, it searched throughprevItemsusing.find(). This resulted in O(N*M) time complexity, which scales poorly when processing a large number of files.📊 Measured Improvement:
We ran a micro-benchmark using 20,000 source files and 20,000 previous items.
PR created automatically by Jules for task 3760722590300373566 started by @mbayue
Summary by cubic
Switched incremental indexing from an O(N*M)
Array.prototype.find()insideArray.prototype.filter()to an O(1) lookup using a precomputedMapkeyed by file path inserver/search/indexing-pipeline.ts. This makes change detection ~155x faster in a 20k-file benchmark.Written for commit b059f87. Summary will update on new commits.