Skip to content

Reduce memory use in anime cadence smoothing - #10

Merged
MONZikWasTaken merged 15 commits into
getflyhigh:mainfrom
NimaJafariComp:optimize/cadence-workspace
Nov 20, 2026
Merged

MONZikWasTaken merged 15 commits into
getflyhigh:mainfrom
NimaJafariComp:optimize/cadence-workspace

Conversation

@NimaJafariComp

@NimaJafariComp NimaJafariComp commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

This follows #8, which adds the live and peak allocation counters I used for the measurements below. I opened this as a draft so the memory reporting and the cadence changes can be reviewed separately. Until #8 lands, the branch includes those commits. Cadence-only diff

Anime cadence smoothing keeps three neighboring pairs available. It was retaining three sets of model weights, inference scratch, and render buffers even though it only runs one plan at a time. I started by comparing pixels and retiming decisions on drawings held for two or three frames, pans, cuts, and seeks, then changed one part at a time.

What changes

  • Share packed model weights and one render target across the three plans.
  • Reuse transient inference buffers within the stream. Keep motion, features, repair maps, and protection state private whenever a later frame still reads them. If the allocation layout doesn't match, keep private arenas.
  • Save the background before rendering the element, as before. The final composite writes straight to the RGBA8 texture. I discarded the first shader version because it changed some f16 pixels; the retained version preserved the old rounding and channel order.
  • In a separate commit, attach stats readbacks to their original pair and stream generation. A result can update its own pair while it's still in history, but it can't change a different interval or survive a seek.

1080p results

Native Metal, fixed kernel choices Before After
f16 tracked GPU allocations 425.15 MiB 282.67 MiB
f32 tracked GPU allocations 651.74 MiB 452.22 MiB

Chrome WebGPU f16 used 413.20 → 270.72 MiB in its own matched run, a 34.5% reduction. It returned to 3 KiB after closing the stream. These are engine-tracked allocations, not driver-reserved VRAM.

Native f16 and f32 matched baseline pixel fingerprints and retiming decisions on the controlled animation fixtures. Chrome matched all 28 generated 1080p frame hashes and 14 retiming decisions. The baseline browser build let a stale result change the new interval after a seek. The updated build didn't. Engine and browser-target Clippy, the cadence regressions, and the relevant non-timestamp GPU tests passed.

Windows NVIDIA and real-episode playback throughput are still untested. This doesn't include the separate Metal timestamp fix.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

NimaJafariComp and others added 15 commits November 19, 2026 14:31
The new stream test fails to compile against the existing EngineReport because the memory breakdown is missing.
Track allocation lifetimes through stream slots, the tensor arena, and plan bindings. Keep the cumulative counter for existing hosts and split out cadence scratch so its cost can be isolated from the three video pair plans.

Verified with native stream and arena tests and the browser WASM build on Apple M5. Opening and freeing realtime, video, and cadence streams at 1920x1080 returned the portable-f16 engine to its 3 KiB baseline.
@MONZikWasTaken
MONZikWasTaken marked this pull request as ready for review November 20, 2026 01:08
@MONZikWasTaken
MONZikWasTaken merged commit 4f314b7 into getflyhigh:main Nov 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants