Skip to content

Fewer memory allocations every frame - #102

Merged
seaweeduk merged 1 commit into
masterfrom
perf/fewer-frame-allocations
Nov 22, 2026
Merged

seaweeduk merged 1 commit into
masterfrom
perf/fewer-frame-allocations

Conversation

@seaweeduk

Copy link
Copy Markdown
Owner

During playback, median main-thread allocations fell from 52–79 per frame to 12–13 across two clips, with the menu open and closed.

  • The frame's submission keeps its waits, its signals and the arrays it passes to vkQueueSubmit from one frame to the next (GpuContext::FrameSlot, GpuContext::submit). The submission order is unchanged.
  • GlInterop and DirectVideo keep their barrier lists, and GlInterop::publish keeps its texture lists and compacts inGl_ in place.
  • The menu keeps the view for its next update (Menu::nextView()), and updateMenu fills it in place. update(nextView()) swaps it with view_ instead of copying it, so the strings and lists in both views keep their capacity. Every field is still set every frame. serversSetUp was the only field built up with |=, so StashCommands::fill now resets it first.
  • Menu::update compares tracks field by field, where it used to build two signature strings. StashPages::update compares the write-back status the same way, where it used to build a status string.
  • isPhotoFile (five calls per frame) and hasPackedAlpha (two) no longer copy the file name or make an std::filesystem::path from it. They give the same answers as before.
  • Autofocus::update compares its content key without building it first. The console's pixel path line is written into a string that SettledLine keeps, and it is still printed only after it has stayed the same for a second.

Allocations per frame

Main thread, median per frame between xrWaitFrame calls, counted with an LD_PRELOAD malloc counter. Measured on the desktop under Monado at 120 Hz with 1024 px eyes, about 470 frames with the menu closed and 340 with it open.

Clip Menu Before After
H.264 test clip, one track, short name closed 52 13
open 53 13
Long file name and title, 2 audio tracks and 1 subtitle track with titles, 4 chapters closed 78 12
open 79 13

The Stash write-back comparison only runs with a server set up, and the direct video barriers only run on the Steam Frame, so neither appears in these numbers.

Frame time on the Steam Frame

Main-thread time per frame outside xrWaitFrame, median [min, max] of two launches per build, alternating, at 120 Hz with 3780 px eyes. It was lower on every clip, but within the run-to-run spread, so this is less work per frame rather than a measured speedup. Both builds: every launch at 120 fps, no dropped frames.

Clip Before (ms) After (ms)
8K HEVC 8-bit, hardware 0.306 [0.300, 0.311] 0.288 [0.274, 0.301]
8K HEVC 10-bit, hardware 0.310 [0.300, 0.320] 0.286 [0.268, 0.303]
6K H.264, hardware 0.325 [0.317, 0.333] 0.301 [0.282, 0.319]
4K VP9, software 1.801 [1.770, 1.831] 1.785 [1.737, 1.833]

Known and left as is

  • isPhotoFile() takes a std::string or std::filesystem::path. All callers already supply one of those types; passing a bare string literal would be ambiguous.
  • sameTracks() checks the same fields as the old track signature. A codec-only change on an unselected track still doesn't trigger a dropdown redraw by itself.

Important

AI disclosure

Model Variant Role
anthropic/claude-opus-5-5 high Implementation
openai/gpt-6.2-astra high Independent review

Agent harness OpenCode 2.3.2

@seaweeduk seaweeduk added the performance Faster or smoother (release notes: Performance) label Nov 22, 2026
@opencode-agent

Copy link
Copy Markdown

LGTM 👍

The reused submission and barrier arrays are cleared before reuse, preserving semaphore order, image layouts, and ownership transfers. The menu compares the incoming view with the displayed one before swapping them, and serversSetUp is rebuilt each frame, so removing a server clears its bit. The filename checks, autofocus key comparison, and one-second logging delay also preserve their prior behavior.

github run

@seaweeduk
seaweeduk force-pushed the perf/fewer-frame-allocations branch from 1a58b8e to 585cce4 Compare November 22, 2026 20:14
@seaweeduk
seaweeduk force-pushed the refactor/wave-5 branch 2 times, most recently from 53e2f9e to e635c6a Compare November 22, 2026 20:59
@seaweeduk
seaweeduk force-pushed the perf/fewer-frame-allocations branch from 585cce4 to b996cce Compare November 22, 2026 20:59
@seaweeduk
seaweeduk changed the base branch from refactor/wave-5 to master November 22, 2026 20:59
@seaweeduk
seaweeduk merged commit 2cea985 into master Nov 22, 2026
@seaweeduk
seaweeduk deleted the perf/fewer-frame-allocations branch November 22, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Faster or smoother (release notes: Performance)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant