[charts] perf: getSymbol
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.
Deploy preview: https://deploy-preview-15233--material-ui-x.netlify.app/
Generated by :no_entry_sign: dangerJS against 3172137b94c3628b4071837427a53e6d202595da
CodSpeed Performance Report
Merging #15233 will not alter performance
Comparing romgrk:perf-get-symbol (3172137) with master (1ca98d3)
Summary
✅ 3 untouched benchmarks
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
Nice catch. 😱
Just for good measure, I've run the benchmark on my M1 Pro on Chrome:
However, Safari shows more realistic numbers similar to the ones seen by Romaine: