Skip to content

perf(webrtc): scope denormal handling to Opus codec calls - #1651

Draft
theomonnom wants to merge 1 commit into
mainfrom
codex/opus-scoped-denormals-20261110
Draft

theomonnom wants to merge 1 commit into
mainfrom
codex/opus-scoped-denormals-20261110

Conversation

@theomonnom

Copy link
Copy Markdown
Member

TL;DR: Scope subnormal handling to Opus calls: 3.72% less whole-agent CPU in the original-audio-settings experiment, projecting 3.86% more CPU-limited sessions.

  • CPU impact: Matched native builds measured 6.603 → 6.357% of one core per session, a 3.72% reduction (paired-block 95% interval 1.91–6.17%). With inline VAD, 16 kHz input and 128 kb/s output, the isolated reduction was 3.03% (0.83–5.54%). A separate lower-density series measured 3.34% (0.89–5.53%) at those optimized settings.
  • More voice sessions per core/machine: CPU-only projections are +3.86% with the original audio settings and +3.12% with the optimized settings—roughly 100 → 104 or 100 → 103. These are conditional projections, not measured production capacity. Timing gates failed in both controls and candidates; the workload excludes remote provider work, recording, and hosting IPC.
  • Activation: Requires rebuilding the Linux WebRTC artifact. Existing downloaded artifacts are unaffected; this PR does not invent a new WEBRTC_TAG.

Subnormal floating-point values can make Opus processing unnecessarily expensive during audio decay and silence. Wrap the internal encode/decode entry points so x86-64 floating-point builds enable FTZ/DAZ for the codec call and restore the caller's MXCSR afterward. Other architectures and fixed-point builds follow the original implementation. The guard is local to the codec; it does not set a process-wide Python floating-point mode.

The Linux build applies the source patch to the pinned Opus checkout. There is no Python API, sample-rate, bitrate, packetization, or SFU change in this patch. The two audio-setting configurations above are benchmark conditions, not changes made by this PR.

Validation:

  • 39,600 encoded packets and 40,464 decoded PCM frames matched the control across 144 rate/channel/bitrate/complexity/loss/DTX cases, including simulated loss, PLC and FEC. This finite corpus does not prove universal bit identity.
  • Added a standalone C regression test: 128 repeated encoder/decoder lifecycle cycles passed, checking floating-point control restoration on normal, concealment, FEC, malformed-packet and encode-error paths, plus failed initialization.
  • 13 actual-FFI RTC PCM/lifecycle tests passed against the rebuilt candidate.
  • The nested patch applies to Opus 55513e81d8f606bd75d0ff773d2144e5f2a732f5 and reproduces the tested source byte-for-byte. Both modified sources pass Clang syntax checks; the Linux script passes shell syntax validation. No Rust source changed; cargo fmt was unavailable in this toolchain.
  • Whole-agent confirmation: five balanced core rotations, 15 sessions per variant, 64 measured seconds after 8 seconds warmup, one process per AgentSession, standard asyncio. Per-block values and gate failures are retained in tests/opus_denormals_benchmark.json. The CPU counter covers all agent-process threads; profiling and codec-only results are excluded from the gain calculation.

The measured effect is incremental on the existing native patch set (#1645, #1646, #1647), using matched GCC rebuilds of the pinned Opus objects. It is not a standalone vanilla-SDK measurement. The comparisons isolate this guard; they must not be added to percentages from other workloads. Capacity uses 1 / (1 - CPU_reduction) - 1, assuming CPU is limiting and per-session cost stays constant at higher load.

Keep draft pending the full Chromium/GN production build, packaging checks and deployment latency/capacity validation. The experiment rebuilt the actual RTC FFI with matching replacement Opus objects in the pinned WebRTC archive; it did not run the complete Chromium/GN build. In the density series, both default-audio variants failed receive-gap and loop-max gates in 5/15 sessions and playout in 9/15. The control also failed one local interruption-completion gate. These failures were retained, not filtered out.

@github-actions

Copy link
Copy Markdown
Contributor

Changeset format error

Knope requires unquoted package names in changeset front matter and silently ignores entries in any other format, so the following lines would never be released:

  • .changeset/opus-denormal-guard.md line 2: "webrtc-sys": patch should be webrtc-sys: patch

This branch has not been deployed

No deployments
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