joshkel commented on issue #20022:
URL: https://github.com/apache/echarts/issues/20022#issuecomment-2959405493

   I found that I can prevent ECharts from cloning options by using the 
`setPrimitive` function from [zrender](https://www.npmjs.com/package/zrender) 
(the utility and drawing library that ECharts uses). Any objects marked by 
`setPrimitive` will be skipped by the `clone` and `merge` functions that 
ECharts uses.
   
   For example, in React with 
[echarts-for-react](https://www.npmjs.com/package/echarts-for-react):
   
   ```ts
   import type { EChartsOption } from 'echarts';
   import ReactECharts, { type EChartsReactProps } from 'echarts-for-react';
   import * as echarts from 'echarts/core';
   import { util } from 'zrender';
   
   function MyComponent() {
     const option = useMemo(() => {
       const option: EChartsOption = {
         xAxis: {
           type: 'category',
           data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
         },
         yAxis: {
           type: 'value',
         },
         series: [
           {
             data: [150, 230, 224, 218, 135, 147, 260],
             type: 'line',
           },
         ],
       };
   
       util.setAsPrimitive(option);
   
       return option;
     }, []);
   
     return <ReactECharts echarts={echarts} option={option} notMerge />;
   }
   ```
   
   I haven't had much opportunity to test this yet, but all of my manual and 
automated tests pass, and the charts render ~15% faster with much less memory 
usage.
   
   Marking objects as primitive also prevents zrender's `merge` function from 
working on them. Since I use the `notMerge` option (which I believe is a better 
fit for immutable-style usage), I don't think this should be an issue; I've 
verified that charts still update as expected in response to data changes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to