Speed up Graph push/pull per-frame paths#2316
Merged
Merged
Conversation
Cache a one-byte filter kind on FilterContext (source / video sink / audio sink / other) at wrap time, so push/pull no longer reconvert filter.name (a C string) to a Python str and do tuple-membership tests on every frame. Cache the buffer/abuffer source contexts on Graph so push/vpush index a list attribute directly instead of looking them up in _context_by_type each call. Pure internal change, no API or behavior difference. On a trivial buffer->buffersink graph the push+pull round trip drops from ~2.0 to ~1.25 us/frame.
c2df65c to
8445fd1
Compare
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.
What
Two internal optimizations to the filter
Graphper-frame hot paths:FilterContextcaches a one-byte filter kind (source/video sink/audio sink/other) at wrap time, replacing the per-frameself.filter.name in (...)/== "buffersink"checks. Those re-convertedfilter.name(a C string) to a fresh Pythonstrand ran tuple-membership tests on every pushed/pulled frame.Graphcaches the buffer/abuffer source contexts (_video_sources/_audio_sources), sopush/vpushindex a list attribute directly instead of doing a_context_by_typedict lookup per call (and theNoneflush no longer allocates a concatenated list on the per-frame path).Why
The per-frame Python/Cython glue is dwarfed by the actual ffmpeg filtering (done under
nogil), so this won't move the needle on full-size-frame workloads — but it's a clean win for high-throughput cases (many small frames, audio, trivial filters).Impact
No API or behavior change — purely internal.
On a trivial
buffer -> buffersinkgraph (64×64 frames), thepush+pullround trip drops from ~2.0 µs/frame (~500K fps) to ~1.25 µs/frame (~800K fps).Testing
make lintclean.