Repository navigation
Allocate downsampling sample buffers on first use - #4054
Open
changyeon-jo wants to merge 1 commit into
Open
changyeon-jo wants to merge 1 commit into
changyeon-jo wants to merge 1 commit into
Conversation
CDownsampling allocates six intermediate sample buffers sized for 1920x1088 (about 6 MB in total) in its constructor, whether or not Process() is ever called. Encoders with a single spatial layer and no input scaling never call it, yet always pay for these buffers, which is significant on memory-constrained targets. Allocate the buffers on the first call to Process() instead. Behaviour is unchanged when downsampling is used, including the fallback when the allocation fails. Assisted-by: Antigravity:gemini-3-pro
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.
Summary
CDownsamplingallocates six intermediate sample buffers sized for 1920x1088 (about 6 MB in total) in its constructor, even whenProcess()is never called. An encoder with a single spatial layer and no input scaling never downsamples, but still pays for these buffers. This change allocates them on the first call toProcess()instead.Details
AllocateSampleBuffer();m_bNoSampleBufferstarts asfalseand the buffers stayNULL.Process()allocates them right before they are first needed. If the allocation fails,m_bNoSampleBufferis set as before, and the existing fallback path is used.CDownsampling::Process()is only reached throughCVpFrameWork::Process(), which holdsm_mutes, so the lazy allocation is serialized like the existing writes to the sample buffers. If it is never called, the destructor freesNULLpointers, whichWelsFree()already handles.With a single 320x240 spatial layer, peak encoder heap drops from about 7.5 MB to about 1.4 MB (measured with glibc
mallinfo2()), with byte-identical output. This makes the encoder usable on targets with a few MB of RAM.Testing
codec_unittest, built withUSE_ASM=Noon x86_64: 483 tests passed (39 disabled), same as without the change.EncodeFileoutput hash tests with 2 and 4 spatial layers, which exercise the downsampler.