Skip to content

perf(kf): avoid bbox decoding during scale-aware noise refresh - #572

Merged
Borda merged 2 commits into
roboflow:developfrom
JESUSROYETH:perf/current-wh-no-bbox-decode
Aug 20, 2026
Merged

Borda merged 2 commits into
roboflow:developfrom
JESUSROYETH:perf/current-wh-no-bbox-decode

Conversation

@JESUSROYETH

Copy link
Copy Markdown
Contributor

BoTSORTTracklet._current_wh() and McByteTracklet._current_wh() decode a full XYXY box during each scale-aware process/measurement-noise refresh, and then only use its width and height.

The default estimator already stores [x_center, y_center, width, height], so reading width and height straight from that looks like the simpler path. It isn't bit-equivalent though: the existing decoder builds both corners first, and with large centers that changes the rounded subtraction result. I checked this on 27,033 Kalman states captured from a DanceTrack replay, and direct reads changed bits in 25,943 of those calls.

So the fix adds a fast path for the default estimator that reconstructs the same two corner pairs and keeps the original operation order, without allocating the XYXY array. The XYXY and XCYCSR estimators keep the existing decoder as a fallback, and C-BIoU also uses the BoT-SORT tracklet, so it goes through the same path.

Regression tests cover BoT-SORT and McByte, check the uint64 output bits, confirm the fast path does not call state_to_bbox(), and check that the other two state representations — plus a subclass of the default estimator — still go through their decoder. The fast path is scoped to the exact XCYCWHStateEstimator class, not isinstance, so a subclass override isn't bypassed. The changelog records the optimisation.

Validation:

  • 27,033 real states, 15 repetitions of the final _current_wh() method: 1,555.33 ns/call median [1,544.67, 1,573.07] to 545.43 [528.89, 562.81], -64.93%. The measured ranges are disjoint.
  • Seven alternating fresh-process DanceTrack pairs on the final code, 25 sequences / 25,508 frames / 225,148 boxes per run: BoT-SORT 8,524.33 ms median [8,299.91, 8,924.06] to 8,202.17 [7,808.38, 8,326.87] (-3.78%); McByte 10,149.26 [10,116.37, 10,370.00] to 9,670.04 [9,593.48, 10,400.23] (-4.72%). Six of seven pairs were faster for each tracker. Paired deltas were [-12.46%, +0.32%] for BoT-SORT and [-6.88%, +2.47%] for McByte, so process variance is visible and the exact percentages depend on the machine and workload.
  • Output and final Kalman-state hashes matched in each DanceTrack process. Hungarian IoU pairing over 2,059 emitted boxes found minimum IoU 1.0, with zero coordinate-bit or ID mismatches.
  • 120,000 plausible cases across both tracklets and three representations, plus 501,250 arbitrary/special float64 calls, had zero bit mismatches.
  • pytest -m "not integration": 1,557 passed, 3 skipped, 14 deselected. Seventeen repository pre-commit hooks pass; one shebang hook skips because no matching file is present.

@JESUSROYETH
JESUSROYETH requested a review from SkalskiP as a code owner August 19, 2026 22:52
@Borda
Borda requested a balanced review from Copilot August 20, 2026 10:37
@Borda Borda added the enhancement New feature or request label Aug 20, 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 scale-aware noise refresh while preserving bit-exact bounding-box arithmetic.

Changes:

  • Adds allocation-free width/height fast paths for BoT-SORT and McByte.
  • Adds regression coverage for exact arithmetic and estimator fallbacks.
  • Documents the optimization in the changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/trackers/core/botsort/tracklet.py Adds the BoT-SORT fast path.
src/trackers/core/mcbyte/tracklet.py Adds the McByte fast path.
tests/core/test_botsort_tracklet.py Tests bit equivalence and fallback behavior.
CHANGELOG.md Records the performance improvement.

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

Changes:
- Restrict BoT-SORT and McByte allocation-free width/height reconstruction to exact XCYCWH float64 state, falling back to decoder arithmetic for other dtypes and subclasses.
- Add restored-float32, non-positive clamp, and fallback-output regression coverage for both tracklets; clarify the helper docstrings.

Impact:
- Restored non-float64 Kalman states retain the prior float64 decoder behavior and bit-equivalence contract.
- The optimized float64 path remains allocation-free while tests protect clamp and estimator-dispatch behavior.

Verification:
- uv run pytest -m "not integration" — 1528 passed, 5 skipped, 14 deselected, 1108 warnings.
- pre-commit run --all-files — passed.
- git diff --check — passed.
- Remediation artifact validation — passed.

Residual limits:
- Specialist provenance, codemap availability, PR benchmark claims, and non-finite state contract remain explicitly unresolved or deferred in the remediation artifact.

---

Co-authored-by: Codex <[email protected]>
@Borda
Borda merged commit 74f1a37 into roboflow:develop Aug 20, 2026
18 checks passed
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