-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Special case List<ClaimsIdentity> in SelectPrimaryIdentity #111799
base: main
Are you sure you want to change the base?
Conversation
src/libraries/System.Security.Claims/src/System/Security/Claims/ClaimsPrincipal.cs
Show resolved
Hide resolved
Would @AndyAyersMS's work with PGO and stack allocation of enumerators handle this automatically rather than needing to manually handle the special-casing? |
Seems like it should. If you to do type analysis on a collection to try and leverage a struct enumerator that some specific collection type offers you are more or less duplicating what these (not yet merged) changes do. There is PR up for the changes (#111473). They are in fairly decent shape, and they optimize the allocation and much of the overhead for abstract enumeration (provided the actual enumerator methods aren't too complicated -- works nicely for Lists, Arrays, etc). Writeup on the changes in case you want to learn more. |
I lack the expertise to see if that PR would eliminate the enumerator allocation, but I would be in favor of closing this pull request and the associated issue if the JIT is able to handle it. |
Let's hold off on this until Andy's change merges and then validate this isn't actually needed. Thanks. |
It certainly sounds like Andy's change should address this, since I love when we are able to make changes to the BCL/JIT/Runtime that means that the simplest code matches (or overtakes) what complex code is striving to do. |
There's no particular restriction on which collection types can participate -- the optimization currently keys off of the Behind this there is also a limitation from PGO. It will currently only specialize for the most frequently seen type so if a given use site sees a variety of collections and no one type appears more than about 30% of the time, we won't optimize at all. We have ambitions of broadening this too (multi-guess PGO), but that and conditional escape interact with each other and I haven't yet tried to make the combination work well. |
This special-cases
SelectPrimaryIdentity
to avoid allocating an enumerator instance if the underlying list of claims is aList<ClaimsIdentity>
. We only do this if the type is exactly the List, no derived types and noIList<T>
.Fixes #107861