AvaloniaUI / Avalonia.Controls.TreeDataGrid

A combined TreeView/DataGrid for Avalonia.
MIT License
266 stars 54 forks source link

Improve performance of Equals function in IndexPath #269

Closed alvaro-berruezo-unity3d closed 6 months ago

alvaro-berruezo-unity3d commented 6 months ago

What does the pull request do?

Improves the performance of the Equals function, as well as the == and != operations, by pre-calculating the hash code in the constructor and using it to compare the objects.

What is the current behavior?

When two IndexPath objects are compared for equality, the CompareTo method is executed, which can be too slow when comparing a large number of IndexPaths The IndexPaths comparison is a limitation when trying to expand all nodes in a large tree, because it is a very heavily used operation used to convert model indexes to row indexes.

What is the updated/expected behavior with this PR?

In every constructor of the IndexPath we calculate the hash code and store it in a member. Then this member is used whenever we need to compare two IndexPath objects for equality, which is much faster than using the CompareTo method.

alvaro-berruezo-unity3d commented 6 months ago

The performance issue is already fixed by https://github.com/AvaloniaUI/Avalonia.Controls.TreeDataGrid/pull/273 Now the Equals function is not heavily used when expanding rows, so we can discard this PR