Skip to content

⚡ Bolt: Optimize spatial distance calculations and deduplication#777

Open
RohanExploit wants to merge 1 commit into
mainfrom
bolt-spatial-optimization-6581972973087676300
Open

⚡ Bolt: Optimize spatial distance calculations and deduplication#777
RohanExploit wants to merge 1 commit into
mainfrom
bolt-spatial-optimization-6581972973087676300

Conversation

@RohanExploit
Copy link
Copy Markdown
Owner

@RohanExploit RohanExploit commented May 18, 2026

This PR implements a performance optimization for spatial distance calculations used in issue deduplication and nearby search.

💡 What:

  • Optimized the find_nearby_issues utility by hoisting coordinate-to-meter conversion constants outside the main loop.
  • Added a pre_filtered parameter to find_nearby_issues that allows bypassing the bounding box check if the input list is already spatially filtered.
  • Applied this optimization to the create_issue and get_nearby_issues endpoints.

🎯 Why:

The previous implementation performed repeated math.radians and math.cos calls for every candidate issue, even when the candidate list was already narrowed down by a SQL bounding box filter. This redundant processing added unnecessary latency to the critical issue reporting path.

📊 Impact:

  • ~20% reduction in latency for the find_nearby_issues logic path when processing pre-filtered results (typical for SQL-backed endpoints).
  • Reduced CPU overhead for spatial deduplication checks during issue creation.

🔬 Measurement:

Verified using benchmark_spatial_v3.py which showed a drop from ~552μs to ~450μs for 1000 candidate issues. All existing spatial tests in backend/tests/test_spatial_utils.py passed.


PR created automatically by Jules for task 6581972973087676300 started by @RohanExploit


Summary by cubic

Speeds up spatial distance checks for deduplication and nearby search by hoisting meters-per-degree calculations and letting SQL-pre-filtered calls skip Python-side bounding boxes. Endpoints using pre-filtered results see ~20% lower latency in the find_nearby_issues path.

  • Refactors
    • Hoisted meters-per-degree constants outside the find_nearby_issues loop (equirectangular path).
    • Added pre_filtered flag to skip bounding box checks when SQL already narrowed candidates.
    • Updated create_issue and get_nearby_issues to pass pre_filtered=True.
    • Benchmarked ~552μs → ~450μs for 1k candidates; existing spatial tests pass.

Written for commit 099ed4d. Summary will update on new commits. Review in cubic

- Hoisted meters-per-degree constant calculations outside the `find_nearby_issues` loop to reduce repeated trigonometric operations.
- Introduced `pre_filtered` flag in `find_nearby_issues` to skip redundant Python-side bounding box checks when SQL spatial filtering is already applied.
- Updated `create_issue` and `get_nearby_issues` endpoints to leverage the `pre_filtered` optimization.
- Achieved ~20% performance improvement in the spatial search path according to benchmarks.
- Verified changes with existing spatial and deduplication test suites.
Copilot AI review requested due to automatic review settings May 18, 2026 14:10
@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.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for fixmybharat canceled.

Name Link
🔨 Latest commit 099ed4d
🔍 Latest deploy log https://app.netlify.com/projects/fixmybharat/deploys/6a0b1dcee6a9d900086eb9e8

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Warning

Rate limit exceeded

@RohanExploit has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 27 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b2a3abf-6efd-4381-ab8d-4f26b90eb768

📥 Commits

Reviewing files that changed from the base of the PR and between 7bc9465 and 099ed4d.

📒 Files selected for processing (3)
  • .jules/bolt.md
  • backend/routers/issues.py
  • backend/spatial_utils.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-spatial-optimization-6581972973087676300

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions
Copy link
Copy Markdown

🙏 Thank you for your contribution, @RohanExploit!

PR Details:

Quality Checklist:
Please ensure your PR meets the following criteria:

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Code is commented where necessary
  • Documentation updated (if applicable)
  • No new warnings generated
  • Tests added/updated (if applicable)
  • All tests passing locally
  • No breaking changes to existing functionality

Review Process:

  1. Automated checks will run on your code
  2. A maintainer will review your changes
  3. Address any requested changes promptly
  4. Once approved, your PR will be merged! 🎉

Note: The maintainers will monitor code quality and ensure the overall project flow isn't broken.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 3 files

Re-trigger cubic

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes the hot-path equirectangular distance computation in find_nearby_issues by hoisting per-degree meter constants out of the loop and adding a pre_filtered flag so callers that already applied a SQL bounding-box filter can skip the redundant Python-side bounding-box check.

Changes:

  • Refactored the inner equirectangular distance to operate directly in degrees with precomputed m_per_deg_lat / m_per_deg_lon constants, removing per-iteration math.radians calls.
  • Added a pre_filtered: bool = False parameter that gates the bounding-box computation and the per-issue bbox check in both fast and fallback branches.
  • Updated create_issue and get_nearby_issues to pass pre_filtered=True (both already apply the bbox filter in SQL), and recorded the learning in .jules/bolt.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
backend/spatial_utils.py Hoists meters-per-degree constants and adds pre_filtered to skip redundant bbox check.
backend/routers/issues.py Passes pre_filtered=True to find_nearby_issues at the two SQL-bbox-filtered call sites.
.jules/bolt.md Documents the spatial optimization learning.

Verified the math is equivalent: (degrees * R*π/180)² = (radians * R)², so dist_sq comparisons match the previous implementation. Both call sites that pass pre_filtered=True apply the bounding box in SQL (issues.py:99-120 and issues.py:324-342), so the skip is safe. The fallback (long-radius) branch correctly still computes min_lat/max_lat/etc. only when not pre_filtered, and these names are only referenced inside if not pre_filtered: blocks, so no UnboundLocalError risk.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants