Performance is one of the key pillars we consider when developing UI controls. We are committed to continuously look for better strategies to improve the performance of every control we create. In .NET 5, FlexGrid for WPF was reassessed and redesigned to overcome some bottlenecks we found in previous versions.
This blog shows the criteria used to develop our .NET 5 datagrid, FlexGrid, and compares its performance to other WPF datagrids on the market.
The two most important aspects to consider when measuring the datagrid performance are loading and scrolling. Scrolling performance is typically more important since loading occurs only once, but scrolling happens constantly–making it much more visible to users.
Of course, loading is significant too, so it is important to resolve these two aspects together to find a suitable balance.
Since datagrids must support displaying large data sets with millions of items, creating the cells for each item is impractical in terms of load-time and memory consumption. Instead, a technique called UI virtualization is used, which displays only what the user can see.
As the user scrolls the grid, the new viewport is recreated underneath and displayed, giving the user the feeling that it was already there.
UI virtualization is beneficial and necessary for optimized loading performance. Still, it doesn't solve the problem at scrolling time. It's necessary to recreate the visual tree to show the new elements every time a scroll event happens–frequently and in a brief lapse of time.
This means that it is crucial to have a fast layout to show all the cells in the viewport as quickly as possible. Since creating the cells and adding them to the visual tree takes a considerable amount of time, recycling the cells will help us reduce the time involved in computing the layout.
On the other hand, UI virtualization does not solve everything. If we use a huge data source, the row collection will have as many rows as items in the source, and simply creating this number of objects brings loading time penalties.
To avoid this, the model virtualization technique is implemented, which results in delaying the creation of columns and rows until they are needed.
To make performance comparisons, we tested all three of our WPF datagrids and compared them against the Microsoft datagrid. The four datagrids tested are:
These datagrids were tested in a .NET 5 application to ensure that each datagrid shows the same number of cells. Results were averaged from multiple tests.
See the data below to view the initial results for scrolling versus loading for 1,000 rows, 10,000 rows, 100,000 rows, and 1 million rows.
Our performance comparison resulted in the following takeaways:
The .NET 5 FlexGrid now has the most consistent performance for any number of rows and shows the fastest loading and scrolling times in every scenario.
It fixes the problems found in .NET Frameworks regarding loading large data sources through the model virtualization implementation.