Prefer stack storage for highly-contended temporary array#61670
Prefer stack storage for highly-contended temporary array#61670sharwell merged 1 commit intodotnet:mainfrom
Conversation
| var uninst1 = ArrayBuilder<TypeSymbol>.GetInstance(); | ||
| var uninst2 = ArrayBuilder<TypeSymbol>.GetInstance(); | ||
| using var uninst1 = TemporaryArray<TypeSymbol>.Empty; | ||
| using var uninst2 = TemporaryArray<TypeSymbol>.Empty; |
There was a problem hiding this comment.
📝 TemporaryArray<T> stores up to 4 elements on the stack, and only uses ArrayBuilder<T>.GetInstance() for 5 or more elements.
There was a problem hiding this comment.
unrelated, have we looked at all at making these pools thread-local?
There was a problem hiding this comment.
Being pinned to a core might make sense as well.
There was a problem hiding this comment.
There are options there, but it's difficult to implement them without penalizing some other scenario. Stack-based allocations have done a good job of addressing this situation in IDE code, so I would expect them to do the same here.
|
Hey @sharwell, do you mind explaining what did you see in the trace prompted this change? Thanks! |
|
@genlu The trace shows high CPU usage in |
|
@dotnet/roslyn-compiler for second review |
1 similar comment
|
@dotnet/roslyn-compiler for second review |
Fixes AB#1449857