Closed braebo closed 1 year ago
Hmm... that's a hard one. What we would need to check is if the listeners are properly removed or not. You could use the getListeners()
method and check the numbers of elements in the array to see if it matches what it's supposed to be. 11 000 listeners does not feel right but it's hard to say if the problem is with the library or your code...
Do you have a minimal working example that triggers the problem?
Did you finally resolve this problem? If not, could you submit a minimal working example that illustrates the problem?
Hey @djipco so sorry about this! Been absolutely slammed recently.
I believe I've sorted it out for the most part -- after combing through countless tracing logs and performance recordings I noticed that, while the source of the event listeners was quite opaque, the problem seemed to be caused by v8 being overwhelmed and failling to do any GC. By fiddling with the AudioContext lookahead, optimizing certain audio graphs, and replacing various requestAnimationFrame
calls with requestIdleCallback
, I was able to create enough breathing room in the event loop to allow GC to keep up with the midi events and WebAudioApi activity.
While I'm not entirely satisfied with the observablility story nor my lackluster understanding of exactly what's going on, I'm confident enough to say that WebMidi is not the cause of the problem.
Sorry for my delay in getting back to you, and thank you for following up on this! This library is amazing and the work you've done is top notch so thank you again!! 🙏
No worries, I totally understand. I'm glad you found the source of the issue. Cheers!
Description It seems like whenever I enable webmidi.js from ableton in my Tone.js app, the performance slowly degrades and the tempo slows down progressively as midi events start to get clogged up. When I stop Ableton, the events continue to fire and the tempo slowly speeds back upm until the backlog of events is processed.
I'm not sure if this is my fault or not -- but the problem doesn't occur when playing the same midi clips as Tone.js events with webmidi off.
Environment:
Details I took a performance snapshot demonstrating the problem. It shows the heap / # of event listeners climbing over time.
For the curious, the implementation looks like this:
```ts export const RealtimeMidi = () => { let dispose: () => void = () => void 0 const init = async () => { await WebMidi.enable().catch((err) => alert(err)) //· Drums ·············································································¬ const drumMidiMap: RecordI'm hoping there is something obvious that I'm doing wrong here! Any advice would be greatly apreciated. Thanks!