Skip to content

decoder: reuse the planes of a picture that left the reference set - #40

Merged
tannevaled merged 1 commit into
mainfrom
perf-plane-reuse
Nov 10, 2026
Merged

tannevaled merged 1 commit into
mainfrom
perf-plane-reuse

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

decoder: reuse the planes of a picture that left the reference set; a Frame is valid until the next call

Every decoded picture allocated and zeroed three planes (1.4 MB at 1280x720): 82 MB
of the 127 MB a 46-picture decode allocated, and about 10 % of its CPU in
madvise, memclr and page faults. The planes of a picture that was returned by an
earlier call and is neither a reference nor waiting to be output now go to a free
list (bounded at 34) and serve the next picture of that size.

This is a change of contract, stated on decoder.Frame: a Frame is valid until the
next call to Decode or Flush on the same Decoder. The internal decoder keeps the
old behaviour unless SetRecycle(true) (the public decoder sets it), so nothing
else that uses it changes. go-avkit/decode copies every picture out at once, so
it is unaffected. A macroblock a corrupt stream never states keeps the samples of
the picture that was there before instead of zero (documented in the README).

Checked: TestRecyclingChangesNoOutput decodes every conformance clip one access
unit per call with and without reuse and compares every picture;
TestRecyclingBoundsTheBytesAllocated requires less than half the bytes; 69 of 73
JVT streams stay bit-exact (4 pending oops1/go.264#2); race detector clean.
Timing deferred: load above 8 when written.

Needs a MINOR release (a documented lifetime is a contract change below v1).

Refs go-avkit/decode#10

🤖 Generated with Claude Code

… Frame is valid until the next call

Every decoded picture allocated and zeroed three planes (1.4 MB at 1280x720): 82 MB
of the 127 MB a 46-picture decode allocated, and about 10 % of its CPU in
madvise, memclr and page faults. The planes of a picture that was returned by an
earlier call and is neither a reference nor waiting to be output now go to a free
list (bounded at 34) and serve the next picture of that size.

This is a change of contract, stated on decoder.Frame: a Frame is valid until the
next call to Decode or Flush on the same Decoder. The internal decoder keeps the
old behaviour unless SetRecycle(true) (the public decoder sets it), so nothing
else that uses it changes. go-avkit/decode copies every picture out at once, so
it is unaffected. A macroblock a corrupt stream never states keeps the samples of
the picture that was there before instead of zero (documented in the README).

Checked: TestRecyclingChangesNoOutput decodes every conformance clip one access
unit per call with and without reuse and compares every picture;
TestRecyclingBoundsTheBytesAllocated requires less than half the bytes; 69 of 73
JVT streams stay bit-exact (4 pending oops1/go.264#2); race detector clean.
Timing deferred: load above 8 when written.

Needs a MINOR release (a documented lifetime is a contract change below v1).

Refs go-avkit/decode#10

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@tannevaled
tannevaled merged commit b6151d9 into main Nov 10, 2026
13 checks passed
@tannevaled
tannevaled deleted the perf-plane-reuse branch November 10, 2026 14:42
tannevaled added a commit that referenced this pull request Nov 10, 2026
Mid-GOP decode 257 -> 179 ms and 127 -> 16 MB, against ffmpeg -threads 1 at 88 ms
(process start included). Release v0.8.0: #40 documents a Frame as valid until the
next call, a contract change.

Refs go-avkit/decode#10

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

1 participant