⚡️ Speed up method STrack.to_xyah
by 11%
#49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📄 11% (0.11x) speedup for
STrack.to_xyah
insupervision/tracker/byte_tracker/single_object_track.py
⏱️ Runtime :
27.4 microseconds
→24.7 microseconds
(best of5
runs)📝 Explanation and details
o3-mini
We can avoid a full copy of tlwh and a later in‐place modification by directly constructing the target array. In the code below we first convert the input to a float32 array (or assume it already is) and then compute the center x,y and aspect ratio without touching the original data (and without doing extra slice operations). This should provide a small performance benefit, especially when this conversion is called frequently.
Note that the return values remain exactly the same.
Explanation of the changes made:
• Instead of copying tlwh and then modifying slices in place, we compute center_x, center_y and aspect_ratio individually.
• We then create a new numpy array from these computed values so that the output exactly matches the original.
• The function signature is maintained and no other logic is altered.
✅ Correctness verification report:
🌀 Generated Regression Tests Details