Skip to content

⚡ Bolt: [performance improvement] Optimize Array.includes to Set.has in voter filtering#373

Draft
yeboster wants to merge 1 commit into
mainfrom
bolt/perf-array-includes-14849234372810392988
Draft

⚡ Bolt: [performance improvement] Optimize Array.includes to Set.has in voter filtering#373
yeboster wants to merge 1 commit into
mainfrom
bolt/perf-array-includes-14849234372810392988

Conversation

@yeboster

Copy link
Copy Markdown
Contributor

💡 What: Replaced Array.prototype.includes() with Set.prototype.has() inside the Array.prototype.filter() loops in the voters/add/+server.ts and voters/remove/+server.ts API endpoints.

🎯 Why: Using Array.includes inside a filter loop creates an O(N*M) time complexity. Given that both owners (all domain owners) and voters (current participants in a proposal) can be very large arrays, this previously blocked the main thread significantly. By precomputing a Set, the lookup becomes O(1), bringing the overall complexity down to O(N+M).

📊 Impact: Reduces time complexity of the voter filtering operations from O(N*M) to O(N+M). This will result in substantially faster API responses and less server CPU utilization when processing large domain owner and voter lists.

🔬 Measurement: This can be verified by benchmarking the endpoint response times before and after the change with datasets simulating 10,000+ domain owners and voters. The reduction in execution time should be easily measurable using standard node profiling tools.


PR created automatically by Jules for task 14849234372810392988 started by @yeboster

This commit optimizes array filtering in `voters/add/+server.ts` and `voters/remove/+server.ts` by replacing the O(N) `Array.prototype.includes` lookups with O(1) `Set.has` lookups. This improves performance from O(N*M) to O(N+M) when operating on large lists of domain owners and proposal voters, mitigating main thread blocking during these API requests.

The corresponding learning pattern has been documented in the `.jules/bolt.md` journal.

Co-authored-by: yeboster <[email protected]>
@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.

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jun 24, 2026 7:45pm

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