-
Notifications
You must be signed in to change notification settings - Fork 36
Description
This might not be possible to fix with this library, but i'm facing this issue with Firefox where source nodes that are not connected to the output will still be processed and degrade performance over time (it doesn't seem to be an issue in Chrome). You can test it out yourself by doing something like:
setInterval(() => {
source = context.createConstantSource()
source.start(0)
}, 10)Even though the source is not connected to the larger graph, it will still be processed and eventually degrade the performance. If you watch your OS activity monitor, you can see firefox uses more and more performance over time until it eventually crackles up.
Since i see you've got some graph analysis and connection memory already in the library, i'm wondering if it's possible to stop ConstantSourceNodes when they are no longer reachable in the audio graph? and restart them when they become connected. You'd have to replace the node and connections when you restart it since ConstantSourceNodes are single use, but it would fix this nasty performance bug. I don't think this type of thing would be possible with OscillatorNodes or BufferSourceNodes since offset and phase are big issues there.
The solution that i was thinking of would be to maintain a list of active (started) ConstantSourceNodes, and occasionally check if it's still reachable to the destination node by iterating over the tree of connected nodes using get-audio-node-connections and get-audio-param-connections to see if it reaches the destination. if it does not, it can be stopped and removed from the active source list which will also free it up for GC if there are no other references to that node. If there is still a reference to that node then restart it when there is a new connection attached and it becomes reachable again.
I realize that this is quite complicated for an optimization, but i've found this memory leak to cause quite a few performance issues. Also i totally understand if this is not something that you think this library should tackle, feel free to close. i might be able to implement something like this on my side of things using the APIs that you expose.