Skip to content

⚡ Optimize incremental indexing array lookup to Map#85

Merged
mbayue merged 1 commit into
masterfrom
jules-3760722590300373566-e48e4df9
Jul 4, 2026
Merged

⚡ Optimize incremental indexing array lookup to Map#85
mbayue merged 1 commit into
masterfrom
jules-3760722590300373566-e48e4df9

Conversation

@mbayue

@mbayue mbayue commented Jul 4, 2026

Copy link
Copy Markdown
Owner

💡 What:
Optimized the incremental indexing array lookup in server/search/indexing-pipeline.ts by converting the inner O(M) Array.prototype.find() search inside Array.prototype.filter() into an O(1) Map.prototype.get() lookup.

🎯 Why:
The previous implementation filtered sourceFiles and inside the filter callback, it searched through prevItems using .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.

  • Original Implementation: ~2,205 ms
  • Optimized Implementation: ~14.18 ms
  • Speedup: ~155x improvement over the baseline.

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() inside Array.prototype.filter() to an O(1) lookup using a precomputed Map keyed by file path in server/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.

Review in cubic

Co-authored-by: mbayue <70324722+mbayue@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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))
Loading

Re-trigger cubic

@mbayue mbayue merged commit f71c287 into master Jul 4, 2026
9 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.

1 participant