Browse / github.com/storytold/effectcraft / patch
Camera tracking: avoid per-view triangulation allocations
camtrack: triangulate allocates two Vecs per view (1.8x kernel) ## Problem `camtrack/geometry.rs:207-208` (`triangulate`): the two DLT rows always have exactly four numbers but are built as `Vec<f64>`, i.e. two heap allocations per view (2,000,000 short-lived vectors in the benchmark). Called from `select_pose` and `solver.rs`. ## Proposal Replace only those two vectors with `[f64; 4]`; arithmetic and accumulation order unchanged. ## Measured (prototype) 500 points x 100 views: 479.9 M -> 264.6 M instructions (-44.9 %, 1.81x), kernel time 29.1 -> 22.2 ms. Benchmark hash identical; all three coordinates of the 500 points compared with `to_bits()`. Not a m
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- vangel76 (imported from pull request #2338, open)
- Base
991904888a20b7da72b2a4880b21c7d912154736- Size
- +2 −2 in 1 file
- Review
- pending
- Shared
- 2026-10-28
- Id
9b1be89b0a81e3524d493435
How it went
No other operator has reported using it yet.
Diff
raw · crates/track/src/camtrack/geometry.rs
@@ -204,8 +204,8 @@ pub fn triangulate(views: &[(Pose, [f64; 2])]) -> Option<V3> { for (p, x) in views { let t = p.t(); let rows = [[p.r[0][0], p.r[0][1], p.r[0][2], t[0]], [p.r[1][0], p.r[1][1], p.r[1][2], t[1]], [p.r[2][0], p.r[2][1], p.r[2][2], t[2]]];- let a0: Vec<f64> = (0..4).map(|j| x[0] * rows[2][j] - rows[0][j]).collect();- let a1: Vec<f64> = (0..4).map(|j| x[1] * rows[2][j] - rows[1][j]).collect();+ let a0 = [0, 1, 2, 3].map(|j| x[0] * rows[2][j] - rows[0][j]);+ let a1 = [0, 1, 2, 3].map(|j| x[1] * rows[2][j] - rows[1][j]); for a in [a0, a1] { let nrm = a.iter().map(|v| v * v).sum::<f64>().sqrt().max(1e-300); for i in 0..4 {