| Summary: | Regression(r273542) Degraded ScriptProcessorNode performance/quality for (14.0.3+ and iOS 14.4.1+) | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Jack Schaedler <jwschaedler> | ||||||
| Component: | Web Audio | Assignee: | Chris Dumez <cdumez> | ||||||
| Status: | RESOLVED FIXED | ||||||||
| Severity: | Critical | CC: | bfulgham, cdumez, darin, eric.carlson, ews-watchlist, eyal, ggaren, glenn, jer.noble, philipj, sergio, webkit-bug-importer | ||||||
| Priority: | P2 | Keywords: | InRadar | ||||||
| Version: | Safari 14 | ||||||||
| Hardware: | All | ||||||||
| OS: | All | ||||||||
| See Also: |
https://bugs.chromium.org/p/chromium/issues/detail?id=1187016 https://bugs.webkit.org/show_bug.cgi?id=224279 |
||||||||
| Attachments: |
|
||||||||
|
Description
Jack Schaedler
2021-03-17 08:40:50 PDT
Potential regression from http://trac.webkit.org/r273542. Created attachment 423499 [details]
Patch
Comment on attachment 423499 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=423499&action=review r=me > Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp:162 > // Get input and output buffers. We double-buffer both the input and output sides. > unsigned doubleBufferIndex = this->doubleBufferIndex(); > bool isDoubleBufferIndexGood = doubleBufferIndex < 2 && doubleBufferIndex < m_inputBuffers.size() && doubleBufferIndex < m_outputBuffers.size(); > ASSERT(isDoubleBufferIndexGood); > if (!isDoubleBufferIndexGood) > return; This code made it hard for me to understand that doubleBufferIndex is always 0 or 1, and is a simple buffer swapper. It made me think that there are some conditions under which we choose to set doubleBufferIndex to some other value, and those conditions are just not reachable at this point of this function. Which is not true. Since we already have a helper function for doubleBufferIndex(), if we really want to do validation, let's do it in doubleBufferIndex(). For example, we can change doubleBufferIndex() to return std::min(m_doubleBufferIndex, 1). Or we can just remove this nonsense because it is nonsense. > Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp:225 > callOnMainThread([this, doubleBufferIndex = m_doubleBufferIndex, protector = makeRef(*this)] { > - auto locker = holdLock(m_processLock); > + auto locker = holdLock(m_bufferLocks[doubleBufferIndex]); > fireProcessEvent(doubleBufferIndex); It's not ideal to re-read m_doubleBufferIndex here (and a few lines above). Better to capture the local variable doubleBufferIndex instead. They'll always be the same in practice - but capturing the local helps to clarify that we're definitely holding the same lock. (Also kinda funny that we do all that nonsense validation of doubleBufferIndex above and then ignore it here!) > Source/WebCore/Modules/webaudio/ScriptProcessorNode.h:93 > Vector<RefPtr<AudioBuffer>> m_inputBuffers; > Vector<RefPtr<AudioBuffer>> m_outputBuffers; Let's change these Vectors to optional<std::array<2>>, to clarify their relationship to the 2 locks and their use in double buffering. Created attachment 423503 [details]
Patch
(In reply to Chris Dumez from comment #5) > Created attachment 423503 [details] > Patch Requesting review again due to substantial changes based on Geoff's feedback. Comment on attachment 423503 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=423503&action=review r=me I really like this. > Source/WebCore/Modules/webaudio/ScriptProcessorNode.cpp:132 > + for (unsigned i = 0; i < bufferCount; ++i) { > + auto locker = holdLock(m_bufferLocks[i]); > + m_inputBuffers[i] = nullptr; > + m_outputBuffers[i] = nullptr; > + } Nice! Comment on attachment 423503 [details] Patch Clearing flags on attachment: 423503 Committed r274573 (235418@main): <https://commits.webkit.org/235418@main> All reviewed patches have been landed. Closing bug. This is a critical issue for us, our web application makes extensive use of ScriptProcessorNode. Do you have an ETA for this fix? (In reply to Eyal Cohen from comment #10) > This is a critical issue for us, our web application makes extensive use of > ScriptProcessorNode. > > Do you have an ETA for this fix? I am not 100% sure but I think this script processor node fix is indeed in iOS 14.5 beta 7. |