Perf: 30% to 70% speedup for superimpose - #935
Conversation
Merging this PR will regress 0 benchmarks
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | benchmark_superimpose[superimpose_without_outliers] |
16.8 ms | 13.5 ms | +24.3% |
| ⚡ | benchmark_superimpose[superimpose] |
2.4 ms | 2 ms | +24.08% |
| ⚡ | benchmark_match[KmerTable-None] |
329.2 µs | 295.5 µs | +11.41% |
| ⚡ | benchmark_match_kmer_selection[BucketKmerTable(10000)-11*11*1*1***111] |
352.7 µs | 318.7 µs | +10.69% |
| 🆕 | benchmark_superimpose_multi_model[superimpose_homologs] |
N/A | 36.1 ms | N/A |
| 🆕 | benchmark_superimpose_multi_model[superimpose_without_outliers] |
N/A | 86.5 ms | N/A |
| 🆕 | benchmark_superimpose_multi_model[superimpose] |
N/A | 9.1 ms | N/A |
| 👁 | benchmark_cell_list_compute_contacts[MASK] |
16.2 ms | 18.6 ms | -12.84% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing jberg5:faster-superimpose (a90ec2b) with main (2587935)
Footnotes
-
14 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
Looks good and the |
_get_rotation_matriceswas doingnp.sum(fixed[:, :, :, np.newaxis] * mobile[:, :, np.newaxis, :], axis=1)which materializes the fullm*n*3*3intermediate (so if m = 100 and n = 10000 you get 9,000,000 floats). This is expensive!_get_rotation_matricescan be made up to 20x faster if you just do this as a single matmul, since the original implementation was just expressing the same contraction asfixed.T @ mobile(ignoring the batch dimension). BLAS runs the computation directly without materializing the intermediate.This shows up as a 1.3 to 1.7x end to end improvement on
superimposeruntime at various dimensions (thanks Amdahl's law).Tests pass locally. Expect this to not be byte-identical since float reduction order is changing, but the differences are at the level of floating point roundoff.
Claude did some benchmarking on
superimposefor me:x86 — GCP c3-standard-8 (Sapphire Rapids), OpenBLAS 8-thread, best-of-7: