Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Hashtable/ArrayList in AccessKeyManager and remove locks #10000

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Contributor

@h3xds1nz h3xds1nz commented Oct 25, 2024

#10000, would you look at that?

Description

This basically turned into overhaul of AccessKeyManager because unless I've missed a class on threading and read the code incorrectly, there's just a lot of unnecessary overhead within the entire class that deserves to be removed.

  • I've removed the locking when accessing _keyToElements since it is an instance member and all instances are inherently one per thread (AccessKeyManager has a private ctor that is only called via private Current property where the instance is stored in [ThreadStatic] s_accessKeyManager variable. So there should be no way how a different thread can ever gain access to an instance of the dictionary with current code.
  • This means that all methods can inherently be static as they either do not modify state or request the one-per-thread instance from Current and can gain access to the only instance member via the property.
  • AccessKeyInformation is now a readonly struct as there's no reason for it to be mutable.
  • Instead of using untyped ArrayList, we will swap to List<WeakReference<IInputElement>>.
  • Instead of using untyped Hashtable, we will swap to Dictionary<string, List<WeakReference<IInputElement>>>.
  • Instead of using untyped WeakReference, we will use the generic WeakReference<IInputElement>.
  • CriticalGetActiveSource was removed as it duplicates GetActiveSource.
  • Some members in AccessKeyEventArgs / AccessKeyPressedEventArgs were made readonly.

Customer Impact

Increased performance, faster startup, decreased allocations.

Regression

No.

Testing

Local build, testing with access keys.

Risk

Low-to-medium, while the changes are mostly replacements, there are different uses of indexers (Hashtable vs Dictionary) and work with generic WeakReference is different, so reviewers shall pay attention I did do anything that shall change behaviour in that regard though from my testing it seemed fine.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners October 25, 2024 17:33
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant