Title: Bonsai: reduce CPU cost of the proximity snap path by carlopav · Pull Request #9340 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Bonsai: reduce CPU cost of the proximity snap path by carlopav · Pull Request #9340 · IfcOpenShell/IfcOpenShell
X Title: Bonsai: reduce CPU cost of the proximity snap path by carlopav · Pull Request #9340 · IfcOpenShell/IfcOpenShell
Description: Context The GPU snap detection that landed in 4cb6ce703..2b429dc60 replaces object discovery. Raycast.ray_cast_by_proximity survives it and is still the only CPU path that turns a detected object into Vertex / Edge Center / Edge snaps: detect_snapping_points calls it for the object under the cursor, and in plan/section views once per visible element carrying cut or fill decorator data. These three changes reduce the cost of that function and of Cad.intersect_edges_v2, which it calls once per edge. They are independent of how candidates are found, so they apply equally before and after the GPU work. Changes One commit each, each independently revertible: 1. Speed up Cad.intersect_edges_v2. Replace np.cross / np.linalg.norm / np.dot with explicit scalar arithmetic. On 3-element operands numpy spends far more time in its dispatch machinery (normalize_axis_tuple, moveaxis) than on the arithmetic itself. Float64 throughout, so results are unchanged. Also used by wall junctions in tool/model.py. 2. Hoist matrix_world out of the proximity loops. It was copied once per vertex and twice per edge, and cannot change while the loops run. Pure code motion: the copy is still taken, and the obj=None path used by the custom_bmesh callers is preserved. 3. Skip the line-line intersection for edges that cannot snap. Every point of an edge lies within half its length of its midpoint, whose distance to the ray the loop already computes for the Edge Center snap. By the triangle inequality no point can be nearer to the ray than midpoint_distance - edge_length / 2; once that lower bound reaches the snap threshold, intersect_edges_v2 cannot produce a hit. The predicate never rejects an edge that could snap, so snapping results are unchanged. Measurements Being explicit about what is and isn't measured: 3.8x on intersect_edges_v2 (68.95µs → 18.16µs) is a direct microbenchmark of the function and holds. End-to-end figures I collected earlier (per-event call count 52,113 → 1,869; ~370ms → ~70ms) were measured before the GPU rewrite, when ray_cast_by_proximity ran against every candidate object. They no longer describe the current architecture, so I am deliberately not claiming them here. What remains true regardless is that both changes strictly remove work while preserving behaviour. Where I would expect them to still matter most is plan and section views: the cut/fill block in detect_snapping_points came through the rewrite unchanged and still iterates every visible mesh element with cache data, rebuilding a bmesh per object per mouse move. Tests test/tool/test_cad.py — 6 characterization tests for intersect_edges_v2 (skew, crossing, parallel, collinear, 2D input, unnormalised directions), written against the previous implementation before the refactor, so it is verified behaviour-preserving rather than assumed to be. test/tool/test_raycast.py (new) — 5 tests for the early-out, including a randomised search over 3000 edges that samples 21 points along every rejected edge and asserts none lies within the threshold, with a guard so the test cannot pass vacuously. test/tool/test_cad.py test/tool/test_raycast.py — 23 passed. black --line-length 120 clean. Related Supersedes #9004, which fixed the object-origin sort in ray_cast_and_get_closest_to_camera_snaps. The GPU rewrite left that function in the file but nothing calls it any more, so the heuristic it corrected is no longer on a live path. I'll close #9004. 🤖 Generated with Claude Code Real work comparison Pre fix After fix
Open Graph Description: Context The GPU snap detection that landed in 4cb6ce703..2b429dc60 replaces object discovery. Raycast.ray_cast_by_proximity survives it and is still the only CPU path that turns a detected object i...
X Description: Context The GPU snap detection that landed in 4cb6ce703..2b429dc60 replaces object discovery. Raycast.ray_cast_by_proximity survives it and is still the only CPU path that turns a detected object i...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/pull/9340
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c26dbbbf-6441-e196-fe67-48601ff2495f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B906:3FA1F8:91D4C0:C0B436:6B04D442 |
| html-safe-nonce | bb4182f32c693b868c694f82548d796a65a76ac7d9201fa5c0df078f87e2cb54 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTA2OjNGQTFGODo5MUQ0QzA6QzBCNDM2OjZCMDRENDQyIiwidmlzaXRvcl9pZCI6IjQ1OTM1NDU2Mjg4NDc3NTYzNTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5921bd9fde0cf3acc847baca44e5e85c3dd5211a8b98ae95d7f42b1c2b5b403f |
| hovercard-subject-tag | pull_request:4326372979 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/IfcOpenShell/IfcOpenShell/pull/9340/files |
| twitter:image | https://avatars.githubusercontent.com/u/47068848?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/47068848?s=400&v=4 |
| og:image:alt | Context The GPU snap detection that landed in 4cb6ce703..2b429dc60 replaces object discovery. Raycast.ray_cast_by_proximity survives it and is still the only CPU path that turns a detected object i... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 194dacb8acfd3e4d3ffb2704e0b1f10327f0dad690a7142acc7b0e0a2d073965 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 68cfb59cd750dff2f222256898e901425584e5e9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width