Commit 764e7f5
perf(base): speed up isskewa and cache identity matrix in trexp/trlog/rodrigues
trexp/trlog don't have one dominant wasteful generic call like the
isR/trnorm/tr2adjoint/qqmul/qvmul fixes did (#213/#214/#215) - they're
deep call chains (trexp -> isskewa -> vexa -> iszerovec ->
unittwist_norm -> rodrigues -> skew -> rt2tr -> ishom -> isR) where
cost is spread thin across many small layers. Two targeted, verified
wins pulled out of that chain:
- isskewa (validity check trexp runs on se(3) input) had the same bug
ishom had pre-#213: np.linalg.norm on a small fixed matrix, plus an
all(S[-1,:] == 0) array-allocation-and-compare for the bottom row.
Fixed the same way, ~1.9x faster standalone.
- np.eye(3) was rebuilt from scratch on every call in rodrigues (1x),
trexp's V-matrix construction (1x), and trlog (2x), despite only
ever being used as a read-only operand in an addition/multiplication
that produces a new array. Replaced with a module-level constant
_EYE3, used only at call sites where it's provably never mutated or
returned directly (an aliasing hazard if it were) - the four
zero-motion/zero-rotation early-return `np.eye(N)` calls in
rodrigues/trexp are untouched, left as fresh arrays, since they hand
the object directly to the caller.
isskew (the plain, non-augmented so(n) check) was also tried with the
same explicit-arithmetic treatment as isskewa, but did NOT show a
reliable win under min-of-repeats benchmarking - the only cost it
avoids is np.linalg.norm on an already-cheap `S + S.T`, not enough
margin to reliably beat by hand-unrolling. Reverted to the original
implementation rather than keep an unproven "fix".
Net effect, measured old-vs-new in the same process (min of 9 repeats
each, to suppress system jitter after an earlier round of misleading
single-run numbers): isskewa ~1.9x, rodrigues ~1.13x, trexp ~1.05x,
trlog ~1.10x. Real but modest - see the PR description's "further
speedup opportunities" section for what a bigger win here would
actually require.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent fff7009 commit 764e7f5
2 files changed
Lines changed: 50 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
55 | 60 | | |
56 | 61 | | |
57 | 62 | | |
| |||
1355 | 1360 | | |
1356 | 1361 | | |
1357 | 1362 | | |
1358 | | - | |
| 1363 | + | |
1359 | 1364 | | |
1360 | 1365 | | |
1361 | 1366 | | |
| |||
1374 | 1379 | | |
1375 | 1380 | | |
1376 | 1381 | | |
1377 | | - | |
1378 | | - | |
| 1382 | + | |
1379 | 1383 | | |
1380 | 1384 | | |
1381 | 1385 | | |
| |||
1514 | 1518 | | |
1515 | 1519 | | |
1516 | 1520 | | |
1517 | | - | |
| 1521 | + | |
1518 | 1522 | | |
1519 | 1523 | | |
1520 | 1524 | | |
| |||
2774 | 2778 | | |
2775 | 2779 | | |
2776 | 2780 | | |
2777 | | - | |
| 2781 | + | |
2778 | 2782 | | |
2779 | 2783 | | |
2780 | 2784 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
411 | 416 | | |
412 | 417 | | |
413 | 418 | | |
| |||
436 | 441 | | |
437 | 442 | | |
438 | 443 | | |
439 | | - | |
440 | | - | |
441 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
442 | 480 | | |
443 | 481 | | |
444 | 482 | | |
| |||
0 commit comments