Use ValueTask<T> on allocation hot paths#23557
Conversation
jasonmalinowski
left a comment
There was a problem hiding this comment.
Might need more changes and confirmation about RPS.
There was a problem hiding this comment.
Does this need updates to the VisualStudioSetup.Dependencies package? Will it ship a new façade that we need to be ready for in RPS?
There was a problem hiding this comment.
(VS integration test failures imply yes, this needs more façade updates.)
|
@jasonmalinowski I meant to mark this one as a work in progress, to be revisited after merging the other allocation-reducing changes that don't require changes to dependencies. |
|
@sharwell Makes sense. No problem with this going in assuming the paperwork is done though. It'll be good to start getting ValueTask in here. |
|
How are you figuring out which paths to ValueTaskisfy? It seems like thsi would be useful across a lot of the LS. But it's unclear how to drive that, and my concern would be regressing some path that actually needs real async. |
In this case, I'm using AnalyzerRunner and looking for |
6535a16 to
5ee05ef
Compare
5ee05ef to
1aa0c44
Compare
|
@jasonmalinowski My original evaluation of allocation savings understated the value of this pull request by a factor of at least 4. |
1aa0c44 to
255b601
Compare
|
We need to make sure that we discuss the RPS implications of this with @MattGertz. This is a new library reference and very likely to be loading in our measured scenarios. |
|
@jaredpar Yes. I plan to update this pull request as issues come to light until it gets to a point that we can claim a justifiable win. However, I'm having all sorts of problems just getting the tests to pass with it. |
c07e78a to
7f4106c
Compare
Adds System.Threading.Tasks.Extensions as a dependency.
…mplete synchronously
7f4106c to
fce2c4a
Compare
|
Based on the size of this added library (26KiB), I think we have reached a point where the wins may justify the inclusion. |
jaredpar
left a comment
There was a problem hiding this comment.
Need to understand the binding redirect problem CPS hit better before we can merge this.
|
@jaredpar I understand. Just want to use this opportunity to reduce setup authoring work, if possible. |
|
I sent some email offline. |
jasonmalinowski
left a comment
There was a problem hiding this comment.
My signoff remains modulo whatever CLR problems exist which I'm not looped in on.
Do make sure when this merges that we've synced to be ready for the coming insertion -- these insertions often require extra steps; the last time we got surprised by one we caused a lot of chaos with delayed divisional branch snaps.
|
|
||
| // do it async for real. | ||
| return DocumentState.GetSyntaxTreeAsync(cancellationToken); | ||
| return DocumentState.GetSyntaxTreeAsync(cancellationToken).AsTask(); |
There was a problem hiding this comment.
You should probably update src/NuGet/Microsoft.CodeAnalysis.Workspaces.Common.nuspec to state the dependency too. It's "fine" for now in that workspaces depends on common, and it depends on extensions, but if ever somebody "fixes" the core one to not depend on it, this is now broken.
|
@jasonmalinowski The problems appeared to involve ValueTuple, not ValueTask. We are already using ValueTuple without problems so whatever happened with the other project doesn't seem to be impacting us. |
|
@jaredpar Any remaining issues from your side? |
|
@sharwell sorry forgot to remove my hold once we realized the issue was ValueTuple not ValueTask. I'm fine with this assuming that we get RPS buy off here as this will add a DLL load to some scenarios. I'm less concerned about the binding redirects / dependency flow as well. Now that we use our own NuGet packages for bootstrapping you pretty much have to get that all right to pass Jenkins 😄 |
|
@jaredpar I can't figure this one out:
|
| <PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" /> | ||
| <PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" /> | ||
| <PackageReference Include="System.Text.Encoding.CodePages" Version="$(SystemTextEncodingCodePagesVersion)" /> | ||
| <PackageReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" /> |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Now that System.Threading.Tasks.Extensions is referenced, the documentation can contain direct links to ValueTask<TResult>.
|
@sharwell need to add the version string for your new package here https://github.com/dotnet/roslyn/blob/master/src/NuGet/NuGetProjectPackUtil.csproj#L93 The error message is definitely not helpful. I ran into it frequently when working with |
|
@Pilchie for approval. This change trades a one-time 28KiB assembly load for the savings described at the top, and allows us to make similar changes moving forward. |
|
I think this is probably worthwhile, but it will likely still need an exception. Let's wait for Monday, and loop in @MattGertz about the right time to take it (since merging now might block insertions of other changes to |
AnalyzerRunner indicated that these asynchronous paths typically complete synchronously. Measured savings are ~2.5% (~2GiB).
Ask Mode template not completed
Customer scenario
What does the customer do to get into this situation, and why do we think this
is common enough to address for this release. (Granted, sometimes this will be
obvious "Open project, VS crashes" but in general, I need to understand how
common a scenario is)
Bugs this fixes
(either VSO or GitHub links)
Workarounds, if any
Also, why we think they are insufficient for RC vs. RC2, RC3, or RTW
Risk
This is generally a measure our how central the affected code is to adjacent
scenarios and thus how likely your fix is to destabilize a broader area of code
Performance impact
(with a brief justification for that assessment (e.g. "Low perf impact because no extra allocations/no complexity changes" vs. "Low")
Is this a regression from a previous update?
Root cause analysis
How did we miss it? What tests are we adding to guard against it in the future?
How was the bug found?
(E.g. customer reported it vs. ad hoc testing)
Test documentation updated?
If this is a new non-compiler feature or a significant improvement to an existing feature, update https://github.com/dotnet/roslyn/wiki/Manual-Testing once you know which release it is targeting.