ircam-ismm / node-web-audio-api

Web Audio API implementation for Node.js
https://www.npmjs.com/package/node-web-audio-api
BSD 3-Clause "New" or "Revised" License
96 stars 13 forks source link

Fix issue with garbage collection #130

Closed b-ma closed 3 months ago

b-ma commented 3 months ago

cf. #118

Ok this is the ended event logic which produced the issue (I will recheck but I don't think this is critical for other events)

For the record:

AudioScheduledSourceNode are not collected in Scavenge but only in Mark-Compact step, while GainNodes are:

[20747:0x130008000]     6339 ms: Scavenge 9.2 (12.7) -> 8.7 (17.7) MB, pooled: 0 MB, 0.96 / 0.04 ms  (average mu = 1.000, current mu = 1.000) task;
NAPI: NapiGainNode dropped
NAPI: NapiGainNode dropped
// ....
[20747:0x130008000]     8119 ms: Mark-Compact (reduce) 10.1 (17.7) -> 5.0 (10.0) MB, pooled: 0 MB, 3.04 / 1.00 ms  (+ 1.4 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 6 ms) (average mu = 0.999, current mu = 0.999) finalize incremental marking via task; GC in old space requested
NAPI: NapiAudioBufferSourceNode dropped
NAPI: NapiAudioBufferSourceNode dropped
NAPI: NapiAudioBufferSourceNode dropped

Looking at CPU usage with htop (ok it is what it is :), we can even see the performance gain from upstream crate I think

Now the question is, can we fix this somehow or should we drop these events until we find a clean solution....

Next steps:

orottier commented 3 months ago

AudioScheduledSourceNode are not collected in Scavenge but only in Mark-Compact step, while GainNodes are:

This could indicate a circular reference, e.g. an object references a closure while the closure also references the object. This is harder to garbage collect.

I'm fine with a hotfix breaking the ended event if that helps your RPi issues. Does it actually? Have you tested this on RPi?

b-ma commented 3 months ago

Does it actually? Have you tested this on RPi?

Not yet, I will try to find some to do that today but I'm pretty confident, the cracks and their end seemed related to Mark-Compact GC calls

b-ma commented 3 months ago

Ok seems to work on RPi too! I will generalize the pattern to all events and make a release on Friday

orottier commented 3 months ago

Super!