Compute WebAudioUtils::ConvertDecibelsToLinear(dB) using fdlibm_expf(dB * ln(10)/20) instead of fdlibm_powf(10.0f, 0.05f * dB) to improve performance
Categories
(Core :: Web Audio, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox162 | --- | fixed |
People
(Reporter: perf-ai-bot, Assigned: kats)
References
(Blocks 1 open bug)
Details
(Whiteboard: [foofrix:f416b52f-8233-4c37-9304-e3af391c7074][fxpe])
Attachments
(1 external file)
Compute WebAudioUtils::ConvertDecibelsToLinear(dB) using fdlibm_expf(dB * ln(10)/20) instead of fdlibm_powf(10.0f, 0.05f * dB). This avoids general-purpose power computation in DynamicsCompressorKernel's per-frame detector release-rate calculation and above-knee saturation, and also affects its curve setup, gain, and envelope calculations. The implementation retains fdlibm for cross-platform consistency, but floating-point rounding changes: differences depend on the input and are not uniformly bounded by a few ulps. The submitted OfflineAudioContext highpass->compressor->gain measurement reports output differences up to approximately 2e-6 absolute and 7e-6 relative, and reduction differences around 2e-5 dB; these are measurements for that graph, not universal bounds. Outside DynamicsCompressorKernel, AudibilityMonitor uses the helper for its constant -72 dB threshold. This optimization composes with separately skipping unused detector release-rate computation during attack.
Problem
Media-Conferencing's VoiceChat step renders 30 s of stereo audio through an OfflineAudioContext graph with a DynamicsCompressorNode (Source -> Biquad -> Compressor -> Gain -> StereoPanner) and the step time is bound by the MediaTrackGraph thread. In the baseline profile, fdlibm_powf alone was ~28% of the MediaTrackGraph thread's samples during VoiceChat (via WebAudioUtils::ConvertDecibelsToLinear called per sample from DynamicsCompressorKernel::process), the largest single hotspot. With the change, VoiceChat-sync went from 450.0 ms to 366.6 ms median (min 449.1 -> 366.2) in profiled media-tag runs; media-tag score 1.565 -> 1.623 (+3.7%, 4/4 interleaved rounds positive); full SP4-experimental interleaved A/B 4.330 -> 4.365 (+0.82% paired over 6 rounds, 5/6 positive).
Performance
- Benchmark: speedometer4
- Test: sp4-full
- Component: Media
- Local Improvement: 0.85%
Validation
| Reporter | ||
Updated•11 days ago
|
| Reporter | ||
Comment 1•11 days ago
|
||
Please move this bug to the correct component.
Once the Phabricator patch is ready for review, please commandeer it.
| Reporter | ||
Comment 2•11 days ago
|
||
Compute WebAudioUtils::ConvertDecibelsToLinear(dB) using fdlibm_expf(dB * ln(10)/20) instead of fdlibm_powf(10.0f, 0.05f * dB). This avoids general-purpose power computation in DynamicsCompressorKernel's per-frame detector release-rate calculation and abo
| Assignee | ||
Updated•10 days ago
|
| Assignee | ||
Comment 3•7 days ago
|
||
I had claude cook up a microbenchmark to verify these results:
iterations/rep=20000000 reps=7 (best-of)
input range kind old ns/call new ns/call speedup
typical [-60, 12] dB throughput 17.71 2.03 8.71x
latency 30.17 14.37 2.10x
wide [-150, 100] dB throughput 16.49 2.18 7.57x
latency 29.64 15.18 1.95x
The benchmark also computed the max ULP diff in the output between the two versions:
Grid sweep, -200..+100 dB, step 0.001 dB
inputs tested : 300000 (300000 finite results)
bit-different outputs: 246165 (82.06%)
max absolute diff : 0.109375 at 99.4199982 dB
max relative diff : 2.33248625e-06 at -177.505005 dB
max ULP diff : 38 at -186.722 dB (mean 3.8072)
Practical range, -100..+24 dB, step 0.0001 dB
inputs tested : 1240000 (1240000 finite results)
bit-different outputs: 863109 (69.61%)
max absolute diff : 4.76837158e-06 at 23.0547009 dB
max relative diff : 1.22834831e-06 at -82.9649963 dB
max ULP diff : 19 at -96.6132965 dB (mean 1.9535)
I'm assuming the difference in output is minor enough that it's worth taking for the performance benefit here. I'll clean up the patch and put up for review.
| Assignee | ||
Comment 4•6 days ago
|
||
Try push for correctness seems clean too: https://treeherder.mozilla.org/jobs?repo=try&group_state=expanded&revision=08f44c84ee467da2eed36e350d0d33d9ad848286
| Assignee | ||
Updated•6 days ago
|
Updated•6 days ago
|
Updated•19 hours ago
|
Updated•19 hours ago
|
Comment 6•17 hours ago
|
||
| bugherder | ||
Description
•