-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use TemporaryArray<T> instead of ArrayBuilder<T> #48976
Conversation
24cdec1
to
0725634
Compare
0725634
to
3a347d4
Compare
@@ -13,7 +13,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Structure | |||
Inherits AbstractSyntaxNodeStructureProvider(Of WhileBlockSyntax) | |||
|
|||
Protected Overrides Sub CollectBlockSpans(node As WhileBlockSyntax, | |||
spans As ArrayBuilder(Of BlockSpan), | |||
ByRef spans As TemporaryArray(Of BlockSpan), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, tbh, block structure
is theplace i would not expect to see wins. in other words, we're almost always going to be +4 elemetns rights?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing it's going to be perf-neutral for this case, but I like it because it's hit often and helps exercise the non-copyable analyzer we're relying on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm.
BlockSpanCollector.CollectBlockSpans( | ||
context.Document, syntaxRoot, _nodeProviderMap, _triviaProviderMap, spans, context.CancellationToken); | ||
context.Document, syntaxRoot, _nodeProviderMap, _triviaProviderMap, ref Unsafe.AsRef(in spans), context.CancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i'm not opposed to this. but this feels like it would not actually be an perf improvement. the reason being that near all files will have +4 elements in them. as such, we'll always spill to the builder, so we'll only be adding overhead here.
That said, i'm ok with this due to consistency if we just want to use this almost anywhere, accepting that in some cases we'll have a little extra perf hit. One thing that i would think could be interesting (outside of the scope of this pr) is if we ended up having thread-local pools for our underlying builders. That way we would never have a single problem colliding when we returned the builders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we ended up having thread-local pools
Once we switch to .NET Core, I plan to rewrite the pool to have processor core-specific first elements hinted by Thread.GetCurrentProcessorId
. This will have performance similar to thread local storage but without the corresponding working set increase. TemporaryArray<T>
would still be better for small storage since the pool efficiency is reduced as the number of active leases increases.
Azure Pipelines successfully started running 2 pipeline(s). |
...orkspaces/SharedUtilitiesAndExtensions/Compiler/Core/Collections/TemporaryArrayExtensions.cs
Show resolved
Hide resolved
Where can we get a concise description of where |
@jaredpar it should always be better when the array will have to store 4 or less items. This is for two reasons:
You can practically think about it as if this gives you a small stackalloc'ed scratch area for lots of small-collection scenarios. Only once you go past that scratch area do you have the same perf costs that you'd have today with normal ArrayBuilder. |
@jaredpar The This change does not address the fact that a new builder mutable value type could be created for known fixed-size allocations, which would be ideal for cases following the pattern |
@@ -27,7 +27,7 @@ | |||
</PropertyGroup> | |||
<PropertyGroup> | |||
<!-- Versions used by several individual references below --> | |||
<RoslynDiagnosticsNugetPackageVersion>3.3.2-beta1.20528.2</RoslynDiagnosticsNugetPackageVersion> | |||
<RoslynDiagnosticsNugetPackageVersion>3.3.2-beta1.20562.1</RoslynDiagnosticsNugetPackageVersion> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this update bringing in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compiler changes LGTM (commit 5)
This pull requests converts a few uses of
ArrayBuilder<T>
toTemporaryArray<T>
where it is reasonably likely to be beneficial. It is primarily intended for reviewing the overall usability of the new type.