Elmish.WPF
Elmish.WPF copied to clipboard
Consider optimizing additions, removals, and moves in elmStyleMerge
In elmStyleMerge, the use of additions and removals is symmetric except when creating moves where the iteration is over additions and TryGetValue is called on removals.
https://github.com/elmish/Elmish.WPF/blob/63ad86ab1af44a8ebbc8eed710dbdf62b865ccc1/src/Elmish.WPF/ViewModel.fs#L138-L147
Also, the fact that additions has type Dictionary<_,_> is never really used. The closest thing is when its Count property is accessed (in constant time) here.
https://github.com/elmish/Elmish.WPF/blob/63ad86ab1af44a8ebbc8eed710dbdf62b865ccc1/src/Elmish.WPF/ViewModel.fs#L163
Therefore, it might be faster for additions (or symmetrically removals, but let's just stick with additions) to be an F# list.
Additionally, we hardly need to remove from either additions or removals. The code to do add and remove respectively recombines additions with moves and removals with moves. The only thing that depends on removing is when the Count property is called above.
Even so, maybe moves and additions (after all the calls to Remove) could be simultaneously created by using List.partition.
In any case, this is a rather small optimization with low priority.
Thanks! One thing caught my eye:
The closest thing is when its
Countproperty is accessed (in constant time) ... Therefore, it might be faster foradditions... to be an F#list.
If we need Count, wouldn't that make array or ResizeArray better so that we keep the constant-time behavior?
Yes. I think ResizeArray would be a good choice.