[charts] Avoid sub-pixel label overlap check
Avoid sub-pixel label overlap check.
When there are more labels than the width in pixels, it means each label will take up less than a pixel. With this PR, I'm assuming that it makes no sense to have labels that take up less than one pixel, so we just take the first label that fills up a specific pixel and every other subsequent label that shares the same pixel won't even be considered.
This reduces the amount of measurements we need to make to the number of pixels in the drawing area, improving performance for bar charts with loads of potential tick labels.
Results
4x CPU throttling
Before:
getVisibleLabels: 107.2ms
After:
getVisibleLabels: 13.25ms
This results in a 8x speed-up. This huge speed-up is partially because we're no longer exhausting the cache, causing it to be cleared. Since we're now well below the 2000 strings we don't need evict all strings. To make a fairer comparison, I increased the cache size to 10k and getVisibleLabels took 17.5ms, so if we don't account for the cache, there's still a 33% improvement.
With the changes from this PR, the time spent measuring strings will now only scale with the minimum of candidate tick labels and width in pixels. Effectively, in large bar charts, this should cap the number of strings we need to measure to the width of said chart.
Deploy preview: https://deploy-preview-20009--material-ui-x.netlify.app/
Bundle size report
| Bundle | Parsed size | Gzip size |
|---|---|---|
| @mui/x-data-grid | 0B(0.00%) | 0B(0.00%) |
| @mui/x-data-grid-pro | 0B(0.00%) | 0B(0.00%) |
| @mui/x-data-grid-premium | 0B(0.00%) | 0B(0.00%) |
| @mui/x-charts | ▼-12B(0.00%) | 🔺+32B(+0.03%) |
| @mui/x-charts-pro | ▼-12B(0.00%) | 🔺+44B(+0.03%) |
| @mui/x-charts-premium | ▼-12B(0.00%) | 🔺+41B(+0.03%) |
| @mui/x-date-pickers | 0B(0.00%) | 0B(0.00%) |
| @mui/x-date-pickers-pro | 0B(0.00%) | 0B(0.00%) |
| @mui/x-tree-view | 0B(0.00%) | 0B(0.00%) |
| @mui/x-tree-view-pro | 0B(0.00%) | 0B(0.00%) |
Generated by :no_entry_sign: dangerJS against 7b6f8b729f61b253095c557624d1f7d65b3b0214
This pull request has conflicts, please resolve those before we can evaluate the pull request.