Repository navigation
feat: compute convolver tail in large blocks - #1469
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
"Host only. I will post Galaxy S21 numbers for main and this branch (apps/fabric-example, ConvolverIR example) tomorrow morning." will wait till tomorrow then and I will review it |
C++ coverageSmoke suites, Clang source-based coverage.
Lines changed in this pull request
Uncovered changed linespackages/react-native-audio-api/common/cpp/audioapi/core/effects/ConvolverNode.cppLines 181-190 181 if (threadPool_ == nullptr) {
182 return;
183 }
184 for (const auto &convolver : convolvers_) {
! 185 const std::optional<size_t> completedBlock = convolver->takeCompletedTailBlock();
! 186 if (!completedBlock.has_value()) {
187 continue;
188 }
189 // A full queue means the workers are starved; the tail is then simply never published
190 // and process() computes it inline when that block comes up.Lines 188-196 188 }
189 // A full queue means the workers are starved; the tail is then simply never published
190 // and process() computes it inline when that block comes up.
191 (void)threadPool_->trySchedule(
! 192 [convolver, block = *completedBlock] { convolver->computeTail(block); });
193 }
194 }
195 } // namespace audioapiWorkflow run · this comment is updated on every push. |
WPT non-regression comparisonPASS — no regressions · 1 improved section(s) · overall 3431 → 3434 (+3)
Unchanged sections (27)
Baseline: Workflow run · this comment is updated on every push. |
|
Galaxy S21 numbers, as promised. Setup: Galaxy S21 (Exynos 2100, Android 15), Convolver playing:
Dry playback (no convolver), both builds: audio thread 30.1 M instructions. So the convolver costs about 9× fewer cycles (about 922 M → 105 M). The audio thread runs about 18% more instructions, because the head is now 32 partitions instead of 8. I compare cycles and instructions, not CPU %. The governor changed the clock frequency between sessions, and the same dry playback read 3% of a core in one session and 12% in another. Not checked: the xrun count. Both builds sound the same by ear on the device. One session per build, one device, one impulse response. |
|
looks veeery solid, making benchmarks on some lower end devices right now, but I'm impressed |
Closes #1463
mainwithin float rounding.Introduced changes
Convolverbecomes a two-stage partitioned convolver.T = TAIL_BLOCK_FRAMES = 2048.[0, 2T)in 128-frame partitions on the audio thread, as before (32 partitions instead of 8).[2T, L)inT-frame partitions with their own2T-point FFT. An impulse response of2Tframes or fewer has no tail and never touches the pool.Tframes of input,process()runs the tail's forward FFT into a second delay line.ConvolverNode::scheduleTailsthen hands onecomputeTail(block)task to the pool: one task per convolver per tail block (about 23 a second at 48 kHz), not one per quantum (375 a second).Ttime-domain frames in a slot. The audio thread starts playing that blockTframes after its input completed, so the worker has about 43 ms.OfflineAudioContexthas no pool and always takes this path.What changed against the design in #1463
block + 3, and its input is not complete until after this block has been played.computeTail(block)returns early for a block whose input is not complete and for a block the audio thread already rendered.nextTailBlock()is replaced bytakeCompletedTailBlock(), which hands each block out once.dsp::FFT, because an FFT object keeps scratch memory.Open questions from the issue
Convolver.hwhereHEAD_SEGMENTSwas.HEAD_FRAMES = 2 × TAIL_BLOCK_FRAMESis derived from it.Why the output is the same
Split the impulse response as
h = head + tail, where the tail starts at frame2T. Theny = head * x + (g * x)delayed by2T, withg[m] = h[2T + m]. Blockjofg * xdepends only on input frames before(j + 1)T, and it is played over frames[(j + 2)T, (j + 3)T). So every tail block is computable one tail block before it is needed, and the head covers everything that depends on newer input.Every test compares against a direct time-domain convolution, including impulse response lengths of
2T,2T + 1,3T,3T + 1and lengths that are not a multiple ofT, on both the published and the inline path.Max error against a double-precision direct convolution (uniform noise in, uniform noise impulse response, 128-frame blocks):
mainHost benchmark
Apple Silicon, Release build, 4 convolvers (a 4-channel impulse response), 104,859-frame impulse response (2.2 s at 48 kHz), 20 s of audio, pool of 4 workers, callbacks paced in real time. "Total CPU" is all threads of the process, as a share of one core.
T = 1024is the same code with the constant changed.main/ 1024 / 2048main/ 1024 / 2048main/ 1024 / 2048mainfor 4 convolvers whilemainhas no misses.maincomputes every tail inline once a callback is longer than its 8-quantum deadline. With 2048-frame blocks that starts above 32 quanta per callback.Limits of these numbers:
mainand this branch (apps/fabric-example,ConvolverIRexample) tomorrow morning.Notes
ConvolverNode.cpp. I will rebase this on whichever lands first.Tis an absolute frame count and every other size derives from the block size, so it should carry over to a variable render quantum..claude/skills/thread-safety-itc/SKILL.mddescribed the 8-segment prefetch; its convolver section is rewritten for this design.directConvolutioninConvolverTest.cppnow sums in double. With impulse responses of 10,000 frames the float sum was less exact than the convolver, and the comparison failed on the reference's rounding. The tolerance is unchanged.Checklist
release/X.Yonly for fixes to the released version)ConvolverNode)Tests
Run:
ConvolverTest(12 cases: the 5 frommainrewritten for impulse responses long enough to have a tail, and 7 new) andConvolverThreadPoolTest: plain,--tsanand--ubasan.--filter convolver: 182 of 255 pass onmainand on this branch, and the two reports are identical test by test.clang-formatandcpplinton the changed files.Not run:
Summary by CodeRabbit