Closed Bug 997870 Opened 10 years ago Closed 9 years ago

OscillatorNode custom waveform optimizations

Categories

(Core :: Web Audio, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla37

People

(Reporter: rillian, Assigned: padenot)

Details

Attachments

(2 files, 3 obsolete files)

Attached file osc-bench.html
Testing recently I noticed that Firefox is an order of magnitude slower than chrome at the attached benchmark page, both on mobile and on desktop. We should do better.
This testcase uses a constant fundamental frequency, so in this case the wave data need only be fetched once for the block, which is what blink does, instead of fetching for each sample.
Looking at Ralph's benchmark, I noticed it repeatedly creates
OfflineAudioContext that are 10 sample-frames long (the second argument of
OffineAudioContext is in frames, not seconds).

As it happens, we have a greater overhead on OfflineAudioContext
creation/completion than Chrome, and it accounted for most of the slowdown. A
more realistic benchmark for PeriodicWave would be to have an
OfflineAudioContext set to a super-long duration (I used 1000 seconds, that
renders in 2.7 seconds or so), and only have one repetition.

Doing that, we see that we are in the same magnitude (a factor of around 5 in
favor of Chrome). Applying this patch, we are only twice a slow. This patch
basically adds a return value to UpdateParametersIfNeeded so we now know if we
need to refetch the wavetable.

I'm sure we can make it better, but since we are switching basic waveforms to
WaveTables, I'd felt like making sure performance were not regressing a lot.
Attachment #8534346 - Flags: review?(karlt)
Assignee: nobody → padenot
Status: NEW → ASSIGNED
Comment on attachment 8534346 [details] [diff] [review]
Optimize ComputeCustom a little. r=

>-      UpdateParametersIfNeeded(ticks, i);

>+      bool needWavetableUpdate = i == aStart ? true : UpdateParametersIfNeeded(ticks, i);

I expect we still need to call UpdateParametersIfNeeded() when i == aStart.
Attachment #8534346 - Flags: review?(karlt) → review-
Attachment #8534972 - Flags: review?(karlt)
Comment on attachment 8534972 [details] [diff] [review]
Optimize ComputeCustom a little. r=

>     double frequency, detune;
> 
>     bool simpleFrequency = mFrequency.HasSimpleValue();
>     bool simpleDetune = mDetune.HasSimpleValue();
> 
>     // Shortcut if frequency-related AudioParam are not automated, and we
>     // already have computed the frequency information and related parameters.
>-    if (simpleFrequency && simpleDetune && !mRecomputeParameters) {
>+    if (ConstantFrequencyForThisBlock()) {
>       return;
>     }

Now that simpleFrequency and simpleDetune are unused before the early return,
can you move the early return up, please?

>+  bool ConstantFrequencyForThisBlock()

Please change the function name to clarify that it is also considering whether
things have changed since UpdateParametersIfNeeded() was last called.

Perhaps ParametersMayNeedUpdate(), with inverse meaning of the result.
Attachment #8534972 - Flags: review?(karlt) → review+
Update to last version, with comments addressed.
Attachment #8534972 - Attachment is obsolete: true
Attachment #8535569 - Attachment is obsolete: true
Comment on attachment 8536595 [details] [diff] [review]
Optimize ComputeCustom a little. r=

>-      UpdateParametersIfNeeded(ticks, i);

>       mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
>                                                      lowerWaveData,
>                                                      higherWaveData,
>                                                      tableInterpolationFactor);

>+        mPeriodicWave->waveDataForFundamentalFrequency(mFinalFrequency,
>+                                                       lowerWaveData,
>+                                                       higherWaveData,
>+                                                       tableInterpolationFactor);
>+        UpdateParametersIfNeeded(ticks, i);

Need to do UpdateParametersIfNeeded() before waveDataForFundamentalFrequency() to set mFinalFrequency.
Attachment #8534346 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/894be64b069b
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla37
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: