Repository navigation
Mask tracker: keep only the cropped previous frame - #2337
Conversation
step() cloned the whole RGBA frame to remember it (33 MB at 1080p, 133 MB at 4K) and then cropped that clone, although only the region around the outline is ever read. The tracker now stores the previous frame already cropped to the region the next step will use, computed from the updated outline with the same margin and rounding as before, so the crops, and therefore the tracking result, are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Crop-based mask tracking crates/track/src/mask.rs |
MaskTracker calculates a region around the mask, clips it to image bounds, and rejects crops that are too small. It stores the previous crop with its layer offset and uses crops during tracking. A new test checks tracking across frames with a nonzero frame offset. |
Priority:
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Refactor
Possibly related PRs
- storytold/effectcraft#2331: It changes
klt::lk_point, which the mask tracking path uses, and both PRs affect that path.
Suggested reviewers: echelon
Merge Risk: 
Minimal · up to 1c871
-
No identified issue needs resolution before merging, subject to normal checks.
Security architecture risk: 
Low · up to 1c871
-
The change does not introduce permissions or external access in the inspected workflow. It does change recovery behavior when a usable crop cannot be produced, although the application already stops tracking on failure.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — The demonstrated behavioral impact is confined to tracking results and recovery for a tracker instance. The inspected consumer uses motion to update project mask paths, not authorization or credential state; no broader privilege or cross-service exposure was identified along this path.
Trust Boundaries and Controls
- observed — The engine continues to own frame progression and project-path updates. Tracking receives borrowed frames and returns motion; the crop-storage change does not transfer project-write authority into the tracking library.
-
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue [
#2320] requires avoiding the full-frame clone by storing a crop for the next tracking step.crates/track/src/mask.rsaddscrop_region, uses it inMaskTracker::new, and refreshes the crop after each step. The crop preserves the prior rounding, margin, frame offset, and minimum-size checks. The new offset test covers the changed coordinate path. The optional rect-luma optimization is not required by [#2320] and remains outside the stated objective.
Full details: Out of Scope Changes check
-
Explanation
The changes are limited to cropped previous-frame storage, crop-coordinate handling, and a focused tracking test in
crates/track/src/mask.rs. These changes directly support issue [#2320]. No unrelated production behavior or unrelated files are shown in the reviewed changes.
-
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
This PR is one of 17 from a speed audit of
Notes:
|
|
Merged, thank you @vangel76! It landed on |
What
MaskTrackerstores the previous frame already cropped to the region the next step reads, instead of cloning the whole frame.Why
stepcloned the full RGBA frame on every call (33 MB at 1080p, 133 MB at 4K) and then cropped that clone; only the area around the outline is read. The engine already passes cachedArc<Image>frames, so the clone was pure overhead (allocation, page faults, memory bandwidth).How
At the end of
step(and innew) the new frame is cropped withcrop_regionto the region of the updated outline (outline bounds plus the same margin). The next step uses that crop and its offset directly, so it no longer re-crops the previous frame.crop_regionis the former inline crop closure with the same rounding, and the crop of the current frame uses it too, so both crops are the pixels they were before. Outline updates only on success, as before, so a failed step keeps the region.MaskTracker::outlineis a public field; the stored crop follows the outline the tracker itself produced (the engine never edits it between steps).The optional rect-luma helper from the issue is not part of this PR; the crop is a single copy of the region.
Verification
to_bits(1080pfef233e1b21e813c, 4K5db43a434a6121f4) and with non-zero frame offsets (37.5,-12.25and-100,80, 12 steps each:e179d36236686119,d3a7715bf4575004).follows_the_disk_through_a_frame_offsetcovers tracking with a non-zero layer offset.cargo fmt --all --check,cargo clippy -p effectcraft-track --all-targets -- -D warnings,cargo test --release -p effectcraft-trackpass;cargo check -p effectcraft-enginepasses.Numbers
One thread, synthetic footage, base and branch alternated, 3 rounds. Instruction counts barely change (the saving is memory traffic and page faults), so wall time is the figure here; instructions and cycles include frame generation.
Fixes #2320
🤖 Generated with Claude Code
Summary by CodeRabbit