Skip to content

⚡ Optimize intersection function with Set for O(N+M) performance#179

Open
jaruesink wants to merge 1 commit intomainfrom
perf-optimize-intersection-11801755235497494748
Open

⚡ Optimize intersection function with Set for O(N+M) performance#179
jaruesink wants to merge 1 commit intomainfrom
perf-optimize-intersection-11801755235497494748

Conversation

@jaruesink
Copy link
Copy Markdown
Contributor

@jaruesink jaruesink commented Feb 6, 2026

💡 What: Optimized the intersection utility function in packages/components/src/ui/data-table-filter/lib/array.ts to use a Set for lookups instead of Array.prototype.includes.

🎯 Why: The original implementation had a time complexity of O(N*M) due to nested iterations (filter + includes). This becomes inefficient for large arrays. The new implementation reduces the complexity to O(N+M) by creating a Set from the second array, allowing O(1) lookups.

📊 Measured Improvement:
Benchmark with 10,000 items in each array (50% overlap):

  • Baseline: ~81ms
  • Optimized: ~2.2ms
  • Speedup: ~37x

Correctness was verified with unit tests and existing Storybook interaction tests passed successfully.


PR created automatically by Jules for task 11801755235497494748 started by @jaruesink

Summary by CodeRabbit

  • Refactor
    • Optimized data table filtering performance for improved responsiveness when handling large datasets.

Co-authored-by: jaruesink <4207065+jaruesink@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 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.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 6, 2026

Walkthrough

A performance optimization in the array filtering utility that replaces array.includes() with a Set-based lookup to improve intersection operation speed while maintaining identical functionality.

Changes

Cohort / File(s) Summary
Array Utility Optimization
packages/components/src/ui/data-table-filter/lib/array.ts
Replaced includes() with Set-based has() lookup for faster intersection operations; maintains identical functional behavior with improved performance for larger arrays.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A filter hops through arrays so fast,
Sets replace the old includes at last,
O(1) lookups now gleam so bright,
No logic changed, just performance might! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: optimizing an intersection function using Set for improved O(N+M) performance, which directly aligns with the core modification in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perf-optimize-intersection-11801755235497494748

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

📝 Storybook Preview: View Storybook

This preview will be updated automatically when you push new changes to this PR.

Note: The preview will be available after the workflow completes and the PR is approved for deployment.

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