Addepar / ember-charts

https://opensource.addepar.com/ember-charts/
Other
784 stars 131 forks source link

Use d3 path, don't use .data( during teardown #237

Closed mixonic closed 5 years ago

mixonic commented 5 years ago

The teardown step was calling not only the d3 selector code, but also data( and its argument. This means at teardown we're forcing re-computation of the rendered data. This is expensive, and additionally may not always reliably work (since the UI is in the middle of teardown state is kind of wonky).

Calling data( is not required however, only the d3 selector need to be called.

I confirmed the memory leak fix isn't regressed with this change. For these charts I'm running the test suite and clicking the GC button around ten seconds. The number of nodes steadily increases, but you expect that to happen running QUnit. It doesn't appear skipping data( during teardown changes any behavior.

Before any of the memory leak work you can see listeners barely drop when GC is triggered:

Screen Shot 2019-05-10 at 1 39 16 PM

Master you can see them drop sharply:

Screen Shot 2019-05-10 at 1 32 29 PM

This PR the same:

Screen Shot 2019-05-10 at 1 33 33 PM
twokul commented 5 years ago

@mixonic good catch sir!