Repository navigation
perf(audio): validate streams without copying discarded PCM - #3194
Merged
richiemcilroy merged 1 commit intoOct 25, 2026
Merged
richiemcilroy merged 1 commit into
richiemcilroy merged 1 commit into
Conversation
Contributor
|
Someone is attempting to deploy a commit to the Cap Software Inc Team on Vercel. A member of the Team first needs to authorize it. |
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.
Export-tail validation calls
AudioStream::read_chunk(48_000)and immediately drops every returned PCM vector. This includes unused source tracks validated byExportAudioSourcesbefore MP4 publication. Decoding and resampling are required to detect failures, but copying validated samples into a new output vector is unnecessary.Extract the existing bounded sample-consumption loop into a private helper. Normal reads still copy samples into their output vector; validation supplies a no-op consumer. Both paths retain the same 48,000-frame checkpoint boundaries, cancellation checks, pending samples, decoder/resampler state machine, sticky failures and reported source positions. No public API or validation step is removed.
Release measurements
Baseline
4d718aa52, Linux x86_64, AMD EPYC 9V74, two-CPU quota, CPU 0 affinity, Rust 1.88.0, FFmpeg 7.1.5. Root release profile (opt-level=s, thin LTO, one codegen unit). Five alternating independent processes per version, 25 samples after three warmups; medians of process medians. Each fixture contains 60 seconds of seeded noise:The resampling/AAC differences are too small to establish a useful CPU improvement in those cases. Validation after reading seven frames first improves 10.1%/18.0% for 48 kHz mono/stereo. Normal
read_chunkcontrols vary from 1.1% slower (mono) to 3.5% faster (stereo); no read-path performance improvement is claimed. All final frame counts match across versions, including AAC's decoded tail. The benchmark times the fullvalidate_to_endcall with warm file cache; stream opening, prefix reads, post-call checks and destruction are outside timing. This is a source-validation result, not an end-to-end export speedup or GPU/capture claim. GPUI's separate level-3 release profile was not benchmarked.A separate instrumented binary counts Rust allocation/reallocation calls only while validating, after opening the stream. PCM fixtures fall from 61 calls to zero; AAC falls from 62 to zero. Cumulative requested Rust allocation bytes fall from 11,712,000 for mono, 23,424,000 for stereo PCM, and 23,808,000 for AAC to zero. These totals sum allocations over the call; they are not peak-live memory figures. FFmpeg's C allocations, stream construction and process RSS are excluded; this is not a claim that decoding performs no allocations.
Correctness and validation
New differential tests compare validation with draining public chunks after partial reads across empty/one-frame inputs, mono/stereo/surround sources, resampling and EOF. An injected decoder failure with 0, 1, 47,999, 48,000, 48,007 and 96,001 pending frames must report the same final frame position and sticky error as normal reads. Existing exact sample-bit, cancellation/private-abort, decoder-tail, relocation/publication and missing-source tests pass.
cargo fmt --all --checkcargo check -p cap-audio --lockedcargo test -p cap-audio --locked: 90 library tests and one doctest pass; three existing benchmarks ignored.cargo clippy -p cap-audio --all-targets --locked -- -D warningsgit diff --checkThe existing vendored RNNoise C build emits its SSE/AVX tuning warning; Rust's strict Clippy gate passes. No unrelated build flags are changed.
Reproduction
Generate reproducible inputs with FFmpeg; use
-threads 1 -filter_threads 1to bound setup work:Copy the example onto the baseline revision, save both binaries, and alternate five runs each. Output includes per-sample API timings, prefix lengths, normal-read controls, and decoded frame counts. Native FFmpeg/ALSA development libraries and libclang are required for this crate. The comparison script and external allocator probe are outside the production diff.
Publication validation: rebased onto
ec15b9840; 91 scoped tests passed, plus formatting, check, and strict all-target Clippy. Benchmarks above were recorded before this rebase; the production paths changed by this PR remain as measured.

Confidence Score: 5/5
The PR appears safe to merge.Summary
AudioStreamnow shares a bounded sample loop between reads and validation. Validation still decodes and resamples audio but skips copying discarded samples.Reviews (1) · Last reviewed commit: "improve(audio): validate streams without..." · Reviewed by Greptile