g200kg / webaudio-tinysynth

Light-weight GM mapped WebAudio-JavaScript Synthesizer Engine / MIDI Player
Apache License 2.0
229 stars 22 forks source link

Memory leaks and performance issues #8

Closed tlindstrom closed 5 years ago

tlindstrom commented 5 years ago

When continuously looping a MIDI track, performance will gradually deteriorate until the browser window starts getting janky, and playback starts glitching. In Chrome, there seems to be a memory leak, which has just been fixed in the latest version of Chromium, causing OscillatorNodes not to be garbage collected under certain circumstances:

https://stackoverflow.com/questions/53241345/web-audio-api-memory-leak?noredirect=1&lq=1 https://bugs.chromium.org/p/chromium/issues/detail?id=717528

If running webaudio-tinysynth in the latest version of Chromium, OscillatorNodes indeed seem to not leak memory anymore. AudioBufferSourceNodes and AudioParams are still piling up however.

In Firefox, I can not see this memory leakage happening in the DevTools, but still, if webaudio-tinysynth is left to play for say, 15 minutes, the music will start glitching for some reason nevertheless.

I love tinysynth, but with these performance issues, I can't really use it. Is this a known problem, and are there any plans to mitigate it? Could something be done to the way a note's audio nodes are cleaned up, in order to ensure garbage collection happens properly?

g200kg commented 5 years ago

Thank you for the report.

As a result of the investigation, I have found the cause of memory leak and fixed it. I do not know if it is perfect or not, but I guess it's no longer to abnormally consume CPU when running for a while with Firefox.

tlindstrom commented 5 years ago

Yeah, that made it go away. Awesome!!