Skip to content

perf(rendering): keep an idle AVAssetReader reader for 5 s unless another track needs its permit - #2986

Merged
richiemcilroy merged 2 commits into
mainfrom
perf/avassetreader-idle-retain
Oct 23, 2026
Merged

richiemcilroy merged 2 commits into
mainfrom
perf/avassetreader-idle-retain

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

An idle AVAssetReaderDecoder throws away its native reader, decoded-frame cache and warm-ahead frames 250 ms after its last request. In the paused editor, almost any pause between hovers or scrub steps is longer than that. The next request then pays for a new reader (4 to 7 ms on the CI VM) and decodes again from a keyframe. In one traced example, a single hover frame after a teardown decoded 61 frames in 65 ms. Pressing Play after a pause also reopens the reader.

Measured on the GPUI editor playback profile (1080p30 fixture, Blacksmith macOS 26 VM): 6 to 6.5 teardowns per 10 s of paused hover, and 9 to 10 in the scrub hunt.

This PR keeps the 250 ms wake-up, but on each wake-up the reader is now released only when:

  • it has been idle for 5 s, or
  • every one of the 16 reader permits is taken, so another track may be waiting for one (the case the short timeout was added for: paused recordings with hundreds of segments).

Behaviour is otherwise unchanged. A request always resets the idle clock, and a released reader is recreated on the next request exactly as before.

Memory: an idle editor holds the frame cache for up to 5 s longer before releasing it, so steady idle memory is unchanged.

Measurements

A/B on ci/editor-playback-ab-idle (run 39955105504): base and head built in one job, 3 interleaved rounds, mean of 3. The fixture is a 40 s 1080p30 studio project, display only and display plus a 720p camera, on a Blacksmith macOS 26 VM.

The "scrub hunt" phase scrubs with 400 ms pauses, like someone looking for a moment:

fixture metric base head
display frames shown (seeks) 128 (183) 206 (204)
display process CPU 37.7% 26.8%
display frames decoded 1858 547
display readers created (time spent) 13 (62 ms) 0
camera frames shown (seeks) 122 (188) 207 (207)
camera process CPU 53.2% 37.3%
camera frames decoded 3371 1096
camera readers created (time spent) 26 (132 ms) 0

The other phases:

  • Paused hover: 16% more frames shown (display 365 to 424, camera 349 to 397), with process CPU within noise (24.3% to 25.3%, 34.0% to 33.6%). Reader creations fell from 4 and 10 to 0.
  • Playback after a pause: no longer reopens the reader (5 ms and 12 ms saved).
  • Forward and backward scrubs: lower process CPU (display forward 57.9% to 46.3%, backward 109.4% to 94.8%) and no reader creations. Forward scrubs decode a few more frames per request, because the kept reader decodes forward instead of reopening at a keyframe.

Memory was not measured by this harness. The frame cache is the same bounded cache as before; it is now released 5 s after the last request instead of 250 ms, so a paused editor's steady memory is unchanged.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Keeps idle AVAssetReaderDecoder readers and cached frames warm for roughly five seconds.

  • Idle AVAssetReader readers stay warm for five seconds unless permits run out.

Reviews (2) · Last reviewed commit: "Merge main into perf/avassetreader-idle-..." · Reviewed by Greptile

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cap-status Ready Ready Preview Oct 23, 2026 5:18pm UTC

@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai review

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@richiemcilroy
richiemcilroy merged commit 3c97fa0 into main Oct 23, 2026
74 checks passed

This branch was successfully deployed

2 active deployments
Preview – cap-web — 8e6320d2 Deployed Oct 23, 2026 by vercel[bot]
Preview – cap-status — 8e6320d2 Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant