⚡ Bolt: Optimize auto_k_selection distance calculations with early exits#132
⚡ Bolt: Optimize auto_k_selection distance calculations with early exits#132teerthsharma wants to merge 1 commit into
Conversation
…sqrt Replaced external `distance` call in the BFS loop of `auto_k_selection` with an inline square distance check. Utilizing an early exit threshold evaluation (`!(sum < eps_sq)`) eliminates costly `libm::sqrt` invocations inside hot neighborhood scanning paths while remaining resilient to NaNs. 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:$O(N^2)$ neighborhood scan. The optimization pre-calculates the squared epsilon (
In
aether-core::ml::clustering::auto_k_selection, thedistance()function which invokeslibm::sqrtwas called repeatedly in aneps_sq) threshold, asserting its validity once before entering the loop. Thesqrtis eliminated completely by checking!(sum < eps_sq)within an inline distance accumulation loop.🎯 Why:
Inside high-frequency geometric neighborhood scans, calling
sqrtcreates significant computational overhead that is fundamentally unnecessary when simple threshold checking is needed.📊 Impact:$O(N^2)$ calls to
Removes
sqrtin the Betti 0 component counting phase, significantly speeding up auto-k discovery.🔬 Measurement:
Running
cargo test -p aether-core clusteringmaintains the correct output while bypassing redundant floating-point operations.Additionally updated the
auto_k_selectionincrement bug to maintain functionality and verified with passing test suites.PR created automatically by Jules for task 8221590513658495514 started by @teerthsharma