⚡ Bolt: Optimize spatial distance calculations and deduplication#777
⚡ Bolt: Optimize spatial distance calculations and deduplication#777RohanExploit wants to merge 1 commit into
Conversation
- 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.
|
👋 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. |
✅ Deploy Preview for fixmybharat canceled.
|
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🙏 Thank you for your contribution, @RohanExploit!PR Details:
Quality Checklist:
Review Process:
Note: The maintainers will monitor code quality and ensure the overall project flow isn't broken. |
There was a problem hiding this comment.
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_lonconstants, removing per-iterationmath.radianscalls. - Added a
pre_filtered: bool = Falseparameter that gates the bounding-box computation and the per-issue bbox check in both fast and fallback branches. - Updated
create_issueandget_nearby_issuesto passpre_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.
This PR implements a performance optimization for spatial distance calculations used in issue deduplication and nearby search.
💡 What:
find_nearby_issuesutility by hoisting coordinate-to-meter conversion constants outside the main loop.pre_filteredparameter tofind_nearby_issuesthat allows bypassing the bounding box check if the input list is already spatially filtered.create_issueandget_nearby_issuesendpoints.🎯 Why:
The previous implementation performed repeated
math.radiansandmath.coscalls 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:
find_nearby_issueslogic path when processing pre-filtered results (typical for SQL-backed endpoints).🔬 Measurement:
Verified using
benchmark_spatial_v3.pywhich showed a drop from ~552μs to ~450μs for 1000 candidate issues. All existing spatial tests inbackend/tests/test_spatial_utils.pypassed.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_issuespath.find_nearby_issuesloop (equirectangular path).pre_filteredflag to skip bounding box checks when SQL already narrowed candidates.create_issueandget_nearby_issuesto passpre_filtered=True.Written for commit 099ed4d. Summary will update on new commits. Review in cubic