-
-
Notifications
You must be signed in to change notification settings - Fork 108
perf: use Attribute[] then List in ToAttributeDictionary
#4303
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
SummaryPerformance optimization to reduce allocations in attribute dictionary creation by using a single-element array instead of a List for the common case of one attribute per type. Critical IssuesNone found ✅ SuggestionsMinor typo in comment (line 29): Consider adding unit tests:
This would help document the behavior and catch any future regressions. Performance validation: Verdict✅ APPROVE - No critical issues This is a solid performance improvement for a hot path (test discovery/building). The logic is correct:
The implementation maintains backward compatibility since both Great work on the performance optimization! 🚀 |
|
@thomhurst Do you have any thoughts about removing |
Most attributes types are unique in
ToAttributeDictionaryso we default to a single array and then switch to aList<Attribute>when a type has more that one attributes. Lists with 1 element added are 32 bytes with an additional 4 element, 56 byteAttribute[].Might be able to pre size the dictionary by using an average of all previous final dictionaries, It might be as easy as a static
long Accumulatorandlong Countand the average is inital capacity forDictionaryPlayground.AssemblyInfowere appearing in every testsAttributeFactoryAttributeFactory, Is this in case the attribute is needed in the test or some AOT thing?ReadOnlyDictionary?Before
After