Skip to content

perf(eval): avoid full-coordinate overlap temporaries - #577

Open
JESUSROYETH wants to merge 1 commit into
roboflow:developfrom
JESUSROYETH:perf/box-coordinate-planes
Open

perf(eval): avoid full-coordinate overlap temporaries#577
JESUSROYETH wants to merge 1 commit into
roboflow:developfrom
JESUSROYETH:perf/box-coordinate-planes

Conversation

@JESUSROYETH

Copy link
Copy Markdown
Contributor

_calculate_box_ious currently broadcasts both four-coordinate inputs into two (N, M, 4) arrays, then only reads one plane from each edge. Those temporaries grow fast with the number of boxes.

This patch gets the same width and height directly from the coordinate planes instead. The subtraction order after that stays the same, but now the biggest intermediates are (N, M), not (N, M, 4).

Validation

First I ran develop against itself to check the harness is sane, then 8,000 seeded comparisons covering IoU and IoA, XYXY and XYWH, float32/64 and integer inputs, strided views, different NaN payloads, infinities, signed zero and subnormals. Output bits are exact in every one of them.

I also ran the full similarity matrices and per-sequence CLEAR/HOTA/Identity payloads on 7 MOT17 sequences (2,652 matrices) and 25 DanceTrack sequences (25,508 matrices), and the bit-level digests match develop in all of them.

The existing box suite already covers both public functions, both formats, empty inputs, zero-area boxes and the numeric edge cases, so I did not add new tests for this. pytest -m 'not integration' passes with 1,564 tests, the 4 evaluator integration tests pass, and pre-commit run --all-files is clean.

Performance

CPU-only, Python 3.12.3 / NumPy 1.26.4. I load the inputs before timing, alternate the run order, and run garbage collection before each sample. These are paired medians, full observed range in brackets.

workload develop median [range] this patch median [range] delta paired wins
MOT17 preparation, 7 sequences 210.36 ms [207.85, 215.88] 192.99 ms [189.71, 197.50] -8.26% 15/15
MOT17 preparation + CLEAR/HOTA/Identity 366.07 ms [361.72, 370.76] 348.33 ms [345.91, 350.80] -4.85% 15/15
DanceTrack preparation, 25 sequences 1.14380 s [1.13340, 1.15414] 1.13138 s [1.12461, 1.14251] -1.09% 9/10
DanceTrack preparation + CLEAR/HOTA/Identity 2.42539 s [2.41889, 2.45163] 2.41470 s [2.40129, 2.43428] -0.44% 9/10

The DanceTrack end-to-end effect is small because building the overlap matrix is only a small part of that workload.

At 1000×1000 boxes, peak traced allocation goes from 88.02 MB to 40.02 MB. Local timing for that allocation-heavy case was noisy on its own, but the ranges never overlap: 33.40-172.54 ms/call on develop against 6.97-11.17 ms/call with this patch, over 15 paired runs.

This implementation comes from the TrackEval port in #210. Its correctness tests use small matrices with tolerance comparisons, so they cover the result but don't catch the temporary-allocation cost.

@JESUSROYETH
JESUSROYETH requested a review from SkalskiP as a code owner August 22, 2026 10:14
@Borda
Borda requested a balanced review from Copilot August 23, 2026 12:12
@Borda Borda added the enhancement New feature or request label Aug 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes evaluator box overlap calculations by avoiding large (N, M, 4) temporary arrays.

Changes:

  • Computes intersection width and height from individual coordinate planes.
  • Reduces peak memory usage while preserving IoU/IoA behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants