speed up macOS scrubbing with stricter decoder reuse#1785
Merged
richiemcilroy merged 3 commits intomainfrom May 7, 2026
Merged
speed up macOS scrubbing with stricter decoder reuse#1785richiemcilroy merged 3 commits intomainfrom
richiemcilroy merged 3 commits intomainfrom
Conversation
|
Paragon Review Skipped Hi @richiemcilroy! Your Polarity credit balance is insufficient to complete this review. Please visit https://app.paragon.run to finish your review. |
Comment on lines
+418
to
421
| assert_eq!(decoder_id, 1); | ||
| assert!(needs_reset); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
The new test only covers the "forces reset" path (decoder too far behind). There is no complementary test verifying that a decoder positioned within the 0.5 s window is actually reused (
needs_reset == false). Without that case, a regression that accidentally always resets would still pass the test suite.
Suggested change
| assert_eq!(decoder_id, 1); | |
| assert!(needs_reset); | |
| } | |
| } | |
| assert_eq!(decoder_id, 1); | |
| assert!(needs_reset); | |
| } | |
| #[test] | |
| fn test_custom_reuse_threshold_reuses_decoder_when_within_window() { | |
| let runtime = tokio::runtime::Runtime::new().unwrap(); | |
| let config = MultiPositionDecoderConfig { | |
| path: PathBuf::from("fixture.mp4"), | |
| tokio_handle: runtime.handle().clone(), | |
| keyframe_index: None, | |
| fps: 60, | |
| duration_secs: 20.0, | |
| }; | |
| let mut manager = DecoderPoolManager::new(config); | |
| // Advance decoder 0 to 5.8 s so it sits within the 0.5 s window of 6.0 s. | |
| manager.update_decoder_position(0, 5.8); | |
| let (_, _, needs_reset) = | |
| manager.find_best_decoder_for_time_with_reuse_threshold(6.0, 5, 0.5); | |
| assert!(!needs_reset); | |
| } | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/rendering/src/decoder/multi_position.rs
Line: 418-421
Comment:
The new test only covers the "forces reset" path (decoder too far behind). There is no complementary test verifying that a decoder positioned within the 0.5 s window is actually reused (`needs_reset == false`). Without that case, a regression that accidentally always resets would still pass the test suite.
```suggestion
assert_eq!(decoder_id, 1);
assert!(needs_reset);
}
#[test]
fn test_custom_reuse_threshold_reuses_decoder_when_within_window() {
let runtime = tokio::runtime::Runtime::new().unwrap();
let config = MultiPositionDecoderConfig {
path: PathBuf::from("fixture.mp4"),
tokio_handle: runtime.handle().clone(),
keyframe_index: None,
fps: 60,
duration_secs: 20.0,
};
let mut manager = DecoderPoolManager::new(config);
// Advance decoder 0 to 5.8 s so it sits within the 0.5 s window of 6.0 s.
manager.update_decoder_position(0, 5.8);
let (_, _, needs_reset) =
manager.find_best_decoder_for_time_with_reuse_threshold(6.0, 5, 0.5);
assert!(!needs_reset);
}
}
```
How can I resolve this? If you propose a fix, please make it concise.| ) | ||
| } | ||
|
|
||
| pub fn find_best_decoder_for_time_with_reuse_threshold( |
There was a problem hiding this comment.
This looks like it’s only used within cap-rendering right now; making it crate-private keeps the surface area smaller.
Suggested change
| pub fn find_best_decoder_for_time_with_reuse_threshold( | |
| pub(crate) fn find_best_decoder_for_time_with_reuse_threshold( |
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.
narrows decoder reuse during scrubbing on macOS AVAssetReader by routing scrub requests through a configurable reuse threshold on the multi-position decoder pool (default playback behavior unchanged).
Greptile Summary
This PR speeds up macOS AVAssetReader scrubbing by routing scrub requests through a tighter 0.5 s decoder-reuse window (vs. the 5–10 s window used during linear playback). When no pooled decoder is within 0.5 s of the requested position, the nearest decoder is reset to the target keyframe instead of being walked forward through many frames sequentially.
multi_position.rs:find_best_decoder_for_timeis refactored to delegate to a newfind_best_decoder_for_time_with_reuse_threshold; callers can pass a custom threshold that is clamped to the pool's configured playback threshold, so no out-of-bounds value is possible.avassetreader.rs:select_best_decodergains anis_scrubbingparameter; when true it calls the new threshold variant withSCRUB_REUSE_THRESHOLD_SECS = 0.5, leaving linear playback behavior unchanged.PLAYBACK-FINDINGS.mdshow scrub decode p95 dropping from 231 ms to 47 ms (−79 %) with no regression to linear playback or A/V sync.Confidence Score: 4/5
Safe to merge; the change is isolated to the scrub code path and the linear playback path is demonstrably unaffected.
The refactoring is clean and the threshold clamp prevents callers from accidentally widening the scrub window beyond the pool's playback threshold. The only gap is that the new test covers only the forced-reset case; a complementary test for the reuse case would make the coverage complete, but its absence does not indicate a defect in the shipped logic.
The test block at the bottom of
multi_position.rswould benefit from a second test covering the complementary reuse case.Important Files Changed
find_best_decoder_for_timeto delegate to a newfind_best_decoder_for_time_with_reuse_thresholdmethod; adds a test covering the forced-reset path when the decoder is beyond the 0.5s window.SCRUB_REUSE_THRESHOLD_SECS = 0.5and threadsis_scrubbingintoselect_best_decoder, routing scrub calls through the tighter threshold; call site correctly supplies the scrub-detector's flag.Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "docs(editor): record scrub benchmark res..." | Re-trigger Greptile