apache / echarts

Apache ECharts is a powerful, interactive charting and data visualization library for browser
https://echarts.apache.org
Apache License 2.0
59.52k stars 19.58k forks source link

[Feature] Optional immutableMode to bypass expensive cloning and improve performance #20022

Open sjcobb opened 2 weeks ago

sjcobb commented 2 weeks ago

What problem does this feature solve?

In complex applications using frameworks like React, it is difficult to achieve optimal performance due to expensive cloning operations that have no way to opt out of. If the goal of these cloning operations (example) is to protect ECharts internals from mutations from users of the library, then it may be unnecessary as mutations are an anti-pattern in these contexts.

Having an optional (and initially experimental) property to tell ECharts to bypass cloning would put more responsibility on users to not abuse setOption calls, but could have a high upside for power users struggling with memory / growing JS heap size. It may also help with open memory leak issues: #7002, #10130, #19984, #7125, #18312, #18686, echarts-for-react/issues/533 (these may not actually be memory leaks but are a symptom of lingering performance issues).

What does the proposed API look like?

Introduce an optional immutableMode property to setOption opts, aimed at optimizing performance for large datasets, where charts needs to re-render frequently. A very rough concept can be seen here: https://github.com/sjcobb/echarts/pull/1

Open to feedback on other ideas, my branch is far from a working prototype, but I want to see if this idea has any traction before diving in further.

sjcobb commented 2 weeks ago

You can see below how heap snapshots steadily increase even after garbage collection kicks in, which eventually results in the browser tab crashing:

image

image

Line charts using 'time' axis are especially problematic or it's possible a variable in the Scheduler (maybe related to agentStubMap or an event handler?) needs to be cleaned up. Edit: I found a related time axis bug ticket #19984