perf: eliminate O(n) hot-path scans in graph data management and tracker - #28
Merged
Merged
Conversation
GraphDataManager (issues 1 & 2): - Replace dataPoints: Vector2[] with a fixed-size ring buffer (O(1) eviction vs. O(n) Array.shift reindexing on every oldest-point removal) - Maintain running xMin/xMax/yMin/yMax updated incrementally in O(1); a full O(n) recomputeMinMax() rescan fires only when an evicted point was an axis extreme (rare once the buffer is settled) - applyAxisRangesFromExtremes() replaces the previous updateAxisRanges() full-scan, keeping axis rescaling at O(1) on the 30 Hz tracking path - addDataPoints() updates min/max inline per-point to avoid per-call function overhead in the tight loop OpenCVTracker (issue 3): - Split captureFrame() into drawVideoFrame() (GPU rasterise — fast) and readPixels(x,y,w,h) (CPU readback — expensive) - track() now computes a search window around lastMatchCenter and calls getImageData only over that sub-region, reducing GPU→CPU pixel transfer by ~10–15× for typical template sizes at 30 Hz - Falls back to a full-frame search when no prior match exists or the clamped window cannot contain the template - lastMatchCenter seeded from initFromVideo() so the very first track() call benefits from the windowed path immediately https://claude.ai/code/session_01E8HRtu2MvwhJYDGSu4ucPa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
GraphDataManager (issues 1 & 2):
eviction vs. O(n) Array.shift reindexing on every oldest-point removal)
a full O(n) recomputeMinMax() rescan fires only when an evicted point
was an axis extreme (rare once the buffer is settled)
full-scan, keeping axis rescaling at O(1) on the 30 Hz tracking path
function overhead in the tight loop
OpenCVTracker (issue 3):
readPixels(x,y,w,h) (CPU readback — expensive)
getImageData only over that sub-region, reducing GPU→CPU pixel transfer
by ~10–15× for typical template sizes at 30 Hz
clamped window cannot contain the template
call benefits from the windowed path immediately
https://claude.ai/code/session_01E8HRtu2MvwhJYDGSu4ucPa