Hi,
We have noticed some performance issues when using the Grid in a Salesforce LWC with high volumes of data. Specifically, loading in 5000 records into the grid is taking roughly 20 seconds.
Our investigations have shown that this issue will occur when the data being set on the Grid is a proxied array from the Lightning Locker Service. This is due to a limitation with how proxied arrays are implemented in the Salesforce Lightning Locker Service. We have identified that when you access a single element from a proxied array, then the whole array is iterated over. This means that if you implement a standard
for (let i = 0; i < count; i++)
loop over an array, then the total number of operations is count * count. For an array with 5000 elements, this results in 25,000,000 operations.
It is therefore much more efficient to iterate over arrays using other methods such as forEach() or map(). I have attached a code snippet which demonstrates the issue with arrays in the Lightning Locker Service. We have reported this to Salesforce, but we have doubts as to whether they will be able to change their implementation of the Locker Service to mitigate this issue.
With regards to the grid - we can see that the loadData() function does a standard array loop, which has a heavy performance impact if the data is a Locker Service proxied array. If this were to be changed to be using the Array.forEach() function, then the performance would be vastly improved.
Thanks.