mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[charts] perf: getSymbol

Open romgrk opened this issue 1 year ago • 2 comments

From what I read in https://github.com/mui/mui-x/pull/15220, you seem to use this function in hot codepaths. It's going to hurt the performance to have that many memory allocations all over the place. Also the implementation has a small issue, indexOf(...) || 0 is incorrect, the empty value of indexOf() is -1.

I benchmarked a few different versions to illustrate the difference:

So even a change as small as moving the static line const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /) to the outside of the function makes the function 2-3x faster, and diminishes the amount of time spent doing GC work.

romgrk avatar Nov 02 '24 15:11 romgrk

Deploy preview: https://deploy-preview-15233--material-ui-x.netlify.app/

Generated by :no_entry_sign: dangerJS against 3172137b94c3628b4071837427a53e6d202595da

mui-bot avatar Nov 02 '24 15:11 mui-bot

CodSpeed Performance Report

Merging #15233 will not alter performance

Comparing romgrk:perf-get-symbol (3172137) with master (1ca98d3)

Summary

✅ 3 untouched benchmarks

codspeed-hq[bot] avatar Nov 02 '24 15:11 codspeed-hq[bot]

Nice catch. I saw this earlier and found it odd, but didn't check how often it was used 🤔

Thanks for taking care of it

JCQuintas avatar Nov 03 '24 04:11 JCQuintas

Nice catch. 😱 Just for good measure, I've run the benchmark on my M1 Pro on Chrome: Screenshot 2024-11-04 at 09 51 22

However, Safari shows more realistic numbers similar to the ones seen by Romaine: Screenshot 2024-11-04 at 09 49 42

LukasTy avatar Nov 04 '24 07:11 LukasTy