Calls in SetWarningProperties() have allocation overhead due to multiple enumeration #13151
Labels
Category:Quality Week
Issues that should be considered for quality week
PerfWins
Priority:2
Issues for the current backlog.
Tenet:Performance
Performance issues
Type:DCR
Design Change Request
Milestone
SetWarningProperties()
has the following implementation:There are three calls to
SetArrayValue()
that get passed a chain of Linq calls.SetArrayValue()
has this implementation:The intent is that the array is only written if
values
is not empty. A consequence of the current implementation is that there is some non-trivial work that is duplicated since there is multiple enumeration happening:From the trace you can see that the
Any()
call requires us to repeat all the work after theToArray()
call until the enumerator gets an item. ForOrderBy()
this requires consuming the entire enumerable and allocating the intermediate arrays that will hold the sorted items. The code should be restructured to avoid the multiple enumeration.The text was updated successfully, but these errors were encountered: