⚡ Bolt: Avoid libm::sqrt in ManifoldPoint::is_neighbor#126
Conversation
Optimizes the `is_neighbor` check used in `SparseAttentionGraph::add_point` by comparing squared distances instead of calling the expensive `libm::sqrt`. Includes early exit capabilities and correctly handles NaN/negative thresholds and coordinates. Co-authored-by: teerthsharma <78080953+teerthsharma@users.noreply.github.com>
|
👋 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. |
💡 What: Replaced the
libm::sqrt-based exact distance calculation with an inline squared distance loop inManifoldPoint::is_neighbor. Implemented early exit when the squared distance sum exceeds the squared epsilon (eps_sq) and added robust handling forNaN/negative inputs using!logic.🎯 Why:$O(N)$ loop for every point added, making it a critical hot path for spatial graph construction. The
SparseAttentionGraph::add_pointcallsis_neighborinside ansqrtoperation is expensive and unnecessary for simple threshold comparisons.📊 Impact: Significantly speeds up the sparse attention mechanism by completely avoiding square root operations and short-circuiting dimension evaluation when points are provably outside the radius.
🔬 Measurement: Run
cargo test -p aether-core manifoldto ensure correctness. The performance gain can be seen in microbenchmarks or any workloads generating continuous spatial structures.PR created automatically by Jules for task 6886637532171051806 started by @teerthsharma