Reduce number of exp2 calls for detune effect calculations
Categories
(Core :: Web Audio, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox118 | --- | fixed |
People
(Reporter: karlt, Assigned: karlt)
References
Details
Attachments
(4 files)
Bug 1358149 comment 55 indicates that transcendental function evaluation is having a significant effect on performance. exp2() is a commonly called such function. Skipping the calls in common unnecessary cases can improve performance.
| Assignee | ||
Comment 1•2 years ago
|
||
When recomputing the AudioBufferSourceNode output rate only when necessary, the geometric mean results improve by ~1%, as many of the webaudio benchmarks use AudioBufferSourceNode. Granular synthesis speed improves by 5% or so.
| Assignee | ||
Comment 2•2 years ago
|
||
OscillatorNode already caches its computed frequency so only "Periodic Wave with Automation" and "Substractive synth" benchmarks are repeatedly calculating the detune effect because the frequency is automated. Caching the detune calculation improves speeds by 11-24% and 7-13%. The linked results are the combined effect of skipping ABSN playback rate calculations and OscillatorNode detune calculations, but "Periodic Wave with Automation" and "Substractive synth" do not use ABSN.
| Assignee | ||
Comment 3•2 years ago
|
||
I haven't cached the result of the detune calculation in AudioBufferSourceNode when the playbackRate is changing. AudioBufferSourceNode would recalculate detune a maximum of once per render block, and I expect resampler re-initialization time to swamp detune effect calculation time.
| Assignee | ||
Comment 4•2 years ago
|
||
I considered switching from exp2 to the lower precision exp2f in OscillatorNode, but this function can amplify rounding error. Consider an input a x where x is close to 1 but contains rounding error. For f(x) = 2^(ax), f'(x)/f(x) = a ln 2. Rounding error is attenuated when |detune/1200| < 1 / ln 2. i.e. |detune| ⪅ 1700, so exp2f would be fine for typical moderate values. For a large detune of 10 octaves, however, error is amplified by 10 ln 2 ≅ 7. i.e. almost 3 of the 24 bits of precision would be lost.
| Assignee | ||
Comment 5•2 years ago
|
||
| Assignee | ||
Comment 6•2 years ago
|
||
Depends on D186686
| Assignee | ||
Comment 7•2 years ago
|
||
Depends on D186687
| Assignee | ||
Comment 8•2 years ago
|
||
to avoid the exp2f() call, which was showing up in benchmarks.
Depends on D186688
Comment 10•2 years ago
|
||
Comment 11•2 years ago
|
||
Comment 12•2 years ago
|
||
| bugherder | ||
Comment 13•2 years ago
|
||
Comment 14•2 years ago
|
||
| bugherder | ||
| Assignee | ||
Comment 15•2 years ago
|
||
Something surprising in the OscillatorNode automation benchmark measurements was that they showed a noticeable difference from removing the unnecessary division. Numbers on 64-bit WINNT were
| Base | New | Delta | Confidence | Total Runs | ||
|---|---|---|---|---|---|---|
| Periodic Wave with Automation | 182.14 ± 1.12 | > | 176.71 ± 0.78 | -2.98% | 5.84 (high) | 7 / 7 |
| Substractive synth | 288.71 ± 0.56 | > | 283.71 ± 0.63 | -1.73% | 5.49 (high) | 7 / 7 |
Numbers of other platforms were similar with some variability.
So I experimented with removing another division, but didn't get further improvements.
Description
•