Skip to content
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

Merged
merged 20 commits into from
Jul 6, 2022

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 1, 2022

This drops us from 1.4GB of allocations:

image

to 1.15gb (18% drop)

image

? (previous, EntryState.Cached)
: (replacement, EntryState.Modified);
? (previous, EntryState.Cached, chosePrevious: true)
: (replacement, EntryState.Modified, chosePrevious: false);
Copy link
Member Author

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);
Copy link
Member Author

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.

@CyrusNajmabadi
Copy link
Member Author

@dotnet/roslyn-compiler for reviews please :)

@CyrusNajmabadi
Copy link
Member Author

@jcouv can you ptal? thanks!

private EntryState? _currentState;

private readonly int _requestedCapacity;
Copy link
Member

@jcouv jcouv Jul 6, 2022

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

Copy link
Member

@jcouv jcouv left a 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)

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge (squash) July 6, 2022 18:54
@CyrusNajmabadi CyrusNajmabadi merged commit cd508c4 into dotnet:main Jul 6, 2022
@ghost ghost added this to the Next milestone Jul 6, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the trimAllocations branch July 6, 2022 21:15
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 7, 2022
* 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)
  ...
@allisonchou allisonchou modified the milestones: Next, 17.4 P1 Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants