Skip to content

⚡ Bolt: Optimize is_neighbor#117

Open
teerthsharma wants to merge 1 commit into
masterfrom
bolt-optimize-is-neighbor-12333417451754299127
Open

⚡ Bolt: Optimize is_neighbor#117
teerthsharma wants to merge 1 commit into
masterfrom
bolt-optimize-is-neighbor-12333417451754299127

Conversation

@teerthsharma
Copy link
Copy Markdown
Owner

⚡ Bolt: Optimize is_neighbor

This PR implements a performance optimization in SparseAttentionGraph::add_point's hot path by replacing the libm::sqrt call in ManifoldPoint::is_neighbor with an inline squared distance loop. The loop uses an early exit condition !(sum < eps_sq) to safely and correctly handle NaN values without panics. The libm::sqrt function is very expensive to call in a spatial scan over hundreds of items.

What: Replaced distance(other) < epsilon in ManifoldPoint::is_neighbor with an inline loop checking squared coordinate distance against epsilon * epsilon.
Why: SparseAttentionGraph::add_point iteratively scans existing points via is_neighbor. Avoiding the libm::sqrt call provides significant performance benefits in this $O(N)$ tight loop, especially under heavy load.
Impact: Reduces spatial clustering overhead and avoids heavy math operations for simple neighbor checks.
Measurement: Measured by observing reduced latency in the topological pipeline processing large datasets.


PR created automatically by Jules for task 12333417451754299127 started by @teerthsharma

This commit implements a performance optimization in `SparseAttentionGraph::add_point`'s hot path by replacing the `libm::sqrt` call in `ManifoldPoint::is_neighbor` with an inline squared distance loop. The loop uses an early exit condition `!(sum < eps_sq)` to safely and correctly handle `NaN` values without panics. The `libm::sqrt` function is very expensive to call in a spatial scan over hundreds of items.

What: Replaced `distance(other) < epsilon` in `ManifoldPoint::is_neighbor` with an inline loop checking squared coordinate distance against `epsilon * epsilon`.
Why: `SparseAttentionGraph::add_point` iteratively scans existing points via `is_neighbor`. Avoiding the `libm::sqrt` call provides significant performance benefits in this $O(N)$ tight loop, especially under heavy load.
Impact: Reduces spatial clustering overhead and avoids heavy math operations for simple neighbor checks.
Measurement: Measured by observing reduced latency in the topological pipeline processing large datasets.

Co-authored-by: teerthsharma <78080953+teerthsharma@users.noreply.github.com>
@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.

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