FindCommandBinding is relatively slow
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
This is about `CommandManager.FindCommandBinding(object sender, RoutedEventArgs e, ICommand command, bool execute)`

I do bellieve that there is two things that would vastly improve performance of this method.
Right now, "ClassCommandBindings" are stored in a Dictionary that uses `Type` as a key, and then loops through a CommandBindingCollection to find the binding. This also loops through every base type for commands that arent even registered on class level.
Instead, why not use a `Dictionary)>`,
The only looping required then is to find all bindings for the type using `InstanceOfType`.
The List needs to be in a correct order that so that the type hirarchy related functionality isn't lost.
My main assumption here is that the vast majority of CommandBindings is not class level.
If this is too much of a resturcture, a simple `HashSet` that stores every command that has a class level binding, could be used as a fast path, to avoid the looping.
Second minor improvement would be to turn those Type-Checks to access the "InputBindingsInternal" into is-Checks like
`if (sender is UIElement uiElement) localInputBindings = uiElement.InputBindingsInternal;`
Contributor guide
Assessment
This issue has not been assessed yet.