-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Use generic collections in System.ComponentModel.TypeConverter implementation #63315
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
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-componentmodel Issue DetailsFix #17217 by replacing non-generic collections classes with their generic counterparts. Of specific interest are:
|
...braries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AttributeCollection.cs
Outdated
Show resolved
Hide resolved
...braries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AttributeCollection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseManager.cs
Outdated
Show resolved
Hide resolved
...tem.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs
Outdated
Show resolved
Hide resolved
...s/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerCollection.cs
Outdated
Show resolved
Hide resolved
...ystem.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerOptionService.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs
Outdated
Show resolved
Hide resolved
|
Thanks for working on this. I suggest scaling back the PR to just the replacements that are trivial to prove are correct. There are a myriad of functional and performance differences between what's being replaced and the replacements, and I'm concerned we'll find a number of regressions that slip through as a result. |
983fde1 to
8e808ed
Compare
|
Thanks everyone for the feedback! I've pushed a less ambitious version that converts just two cases:
Additional feedback and thoughts are very welcome. My goal is less change for change's sake, and more to address the spirit of the linked issue (and hopefully close it out). If anyone has any thoughts, questions, or concerns, please let me know. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static dictionaries that contain Type objects must be ConditionalWeakTables, not (Concurrent)Dictionaryies. Otherwise the types are rooted which inhibits unloadability and leads to bugs like #62050.
I have marked some places that should be changed, could you please do that? You can take advantage of the GetValue method; it works similarly to ConcurrentDictionary.GetOrAdd.
s_defaultAttributes is safe to change to CWT as well.
Edit: Oh, you had responded to a comment of mine. I thought you hadn't seen them.
As long as this PR isn't adding additional rooting, I would prefer any changes to address concerns around unloadability be done separately in a dedicated PR. |
eerhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @MattKotsenas.
Most of the files look fine. But 2 of them I'm not 100% sure are better. The 2 I tagged already have locking around modification, which we aren't changing the locking in this PR. I'm not sure we can trivially prove that changing from Hashtable to ConcurrentDictionary is beneficial. Can we revert those two files? We aren't actively investing in System.ComponentModel, and changes here would introduce more risk than the value these changes bring.
Other than that I think the rest of the changes are OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I can trivially prove the changes in this file are correct. Can we revert this file's changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I can trivially prove the changes in this file are correct. Can we revert this file's changes?
|
@MattKotsenas - any response to my above feedback? If you aren't actively working on this PR, I can close it until it is active again. |
|
Hi @eerhardt ! Yes, I'll back out those changes as well and update to resolve conflicts today or tomorrow. Thanks again for all the feedback! |
Also replaced a double dictionary lookup with the `TryGet` variant to increase performance.
8e808ed to
a04bc5c
Compare
|
@eerhardt updated! Please take a look when you get a chance and let me know if you have any thoughts / suggestions. Thanks! |
eerhardt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this slimmed down change is now fine. And with it we should be able to close the long-standing issue.
Thanks for the contribution, @MattKotsenas!
@stephentoub - I will wait for your approval before removing the "No Merge" label. Let me know what you think.
stephentoub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Seems ok. All of those GetValueOrDefault calls are extension method calls resulting in virtual dispatch via IReadOnlyDictionary; it's probably ok given the library.
|
Test failure is #64389. Merging. |
Fix #17217 by replacing non-generic collections classes with their generic counterparts. Of specific interest are:
DictionaryEntryand notKeyValuePairHashtableswere static, I verified that every use was either already under a lock, or switched to aConcurrentDictionaryto more closely match the Hashtable semantics of allowing multiple readers and a single writer