Bug 190552

Summary: UI / DOM blocks audio thread, causing crackles
Product: WebKit Reporter: ae
Component: Web AudioAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Major CC: jer.noble, nchase, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: iPhone / iPad   
OS: iOS 12   

Description ae 2018-10-13 09:14:56 PDT
We're developing a WebAudio-based DAW running in a WKWebView. This works amazingly well and we're thrilled how far the Web Audio API has come.

However, when the engine is under high load (roundabout 500 nodes for the entire loaded project), interacting with the DOM (scrolling, adding / removing elements, etc.) in any way causes severe buffer underruns, even at 1024 frames buffer size (set by starting another app that sets that buffer size and records in the background).

Shouldn't the audio thread run with high priority and not be blocked by the UI / DOM thread?
Comment 1 Radar WebKit Bug Importer 2018-10-17 10:28:47 PDT
<rdar://problem/45342528>
Comment 2 Jer Noble 2018-10-17 12:59:05 PDT
(In reply to ae from comment #0)
> We're developing a WebAudio-based DAW running in a WKWebView. This works
> amazingly well and we're thrilled how far the Web Audio API has come.
> 
> However, when the engine is under high load (roundabout 500 nodes for the
> entire loaded project), interacting with the DOM (scrolling, adding /
> removing elements, etc.) in any way causes severe buffer underruns, even at
> 1024 frames buffer size (set by starting another app that sets that buffer
> size and records in the background).
> 
> Shouldn't the audio thread run with high priority and not be blocked by the
> UI / DOM thread?

Can you provide sample code? Unless you're using javascript-based nodes, WebAudio should be entirely off the main-thread.
Comment 3 ae 2018-10-18 04:49:37 PDT
(In reply to Jer Noble from comment #2)
> (In reply to ae from comment #0)
> > Shouldn't the audio thread run with high priority and not be blocked by the
> > UI / DOM thread?
> 
> Can you provide sample code? Unless you're using javascript-based nodes,
> WebAudio should be entirely off the main-thread.

Thanks, I will try to put together a testcase. Essentially though, it should be easy: Just create ~ 500 mixed nodes (oscillators, gains, filters, etc.), start all the oscs and make connections so it all actually uses CPU, run all of that in a WKWebView, and then do some manipulation on a DOM with ~ 1000 nodes, or some heavy redrawing in a <canvas>, that should be enough to trigger the problem.
Comment 4 ae 2018-10-18 04:50:19 PDT
Oh, not using any ScriptProcessor nodes!
Comment 5 ae 2018-12-14 15:07:48 PST
I've realized that this is not even related to the DOM at all -- even pressing one of the volume buttons on a connected headset leads to massive crackles during the fade in and fade out animations of the iOS volume overlay! So it seems like in general, the whole WKWebView Web Audio thread is not decoupled from UI rendering, no matter where it happens...