perf: use Attribute[] then List in ToAttributeDictionary#4303
perf: use Attribute[] then List in ToAttributeDictionary#4303thomhurst merged 1 commit intothomhurst:mainfrom
Attribute[] then List in ToAttributeDictionary#4303Conversation
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