-
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
Reuse prior TableEntry values in the increment NodeTable builder if possible. #62320
Conversation
? (previous, EntryState.Cached) | ||
: (replacement, EntryState.Modified); | ||
? (previous, EntryState.Cached, chosePrevious: true) | ||
: (replacement, EntryState.Modified, chosePrevious: false); |
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.
note: chosePrevious is technically redundant. we can tell waht happened by seeing if we got EntryState.Cached
or EntryState.Modified
back. But i was worreid that was too confusing/brittle, so i went this path.
@@ -578,15 +620,24 @@ public void Add(T item, EntryState state) | |||
} | |||
else if (_currentState != state) | |||
{ | |||
_states = ArrayBuilder<EntryState>.GetInstance(_items.Count - 1, _currentState.Value); |
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.
this approach was an anti pattern. by doing GetInstance(_items.Count - 1)
we were always allocating an array one too small for what we needed. The adding a value would force us to double and then copy and then throw that initial array away.
The new form both avoids that, and avoids any wastage entirely by ensuring we use _requestedCapacity to get exactly the size we need.
@dotnet/roslyn-compiler for reviews please :) |
@jcouv can you ptal? thanks! |
private EntryState? _currentState; | ||
|
||
private readonly int _requestedCapacity; |
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.
This is only used in DEBUG mode for assertions. Can we if/def?
Ignore that. I'd missed a usage. #Closed
src/Compilers/Core/Portable/SourceGeneration/Nodes/NodeStateTable.cs
Outdated
Show resolved
Hide resolved
src/Compilers/Core/Portable/SourceGeneration/Nodes/NodeStateTable.cs
Outdated
Show resolved
Hide resolved
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.
LGTM Thanks (iteration 18)
* upstream/main: (62 commits) Prevent assert from being hit (dotnet#62366) Don't offer '??=' for pointer types (dotnet#62476) Integrate generator times into /reportAnalyzer (dotnet#61661) Switch to a callback for cleaning up resources instead of passing in an explicit IDisposable. (dotnet#62373) Filter trees to only those containing global-usings or attributes prior to analyzing them. (dotnet#62444) Update PublishData.json Complete 'file' support for `SyntaxGenerator` (dotnet#62413) Apply changes directly to text buffer (dotnet#62337) Remove LangVer check from extended nameof binding (dotnet#62339) Fixed shared project file error (dotnet#62466) Handle new error codes Use MSBuid generated property for package path Exclude BCL libraries from Roslyn vsix Bump the integration test timeouts a bit Skip the balanced switch dispatch optimization for patterns on floating-point inputs (dotnet#62322) Test helpers shouldn't escape quotes by default (dotnet#62321) Reuse prior TableEntry values in the increment NodeTable builder if possible. (dotnet#62320) Install 3.1 runtime for SBOM tool Generate VS SBOM during official build. Minor refactoring in 'required' handling for override completion (dotnet#62422) ...
This drops us from 1.4GB of allocations:
to 1.15gb (18% drop)