Skip to content

Avoid creating dependent slots in NullableWalker#48920

Merged
cston merged 2 commits intodotnet:masterfrom
cston:GetOrCreateSlot
Oct 27, 2020
Merged

Avoid creating dependent slots in NullableWalker#48920
cston merged 2 commits intodotnet:masterfrom
cston:GetOrCreateSlot

Conversation

@cston
Copy link
Contributor

@cston cston commented Oct 26, 2020

Avoid creating dependent slots in NullableWalker.MarkDependentSlotsNotNull.

When compiling src/Compilers/CSharp/Portable, reduces elapsed time by ~13% and reduces total allocations by ~20%.

@cston cston marked this pull request as ready for review October 26, 2020 22:48
@cston cston requested a review from a team as a code owner October 26, 2020 22:48
@RikkiGibson RikkiGibson self-assigned this Oct 26, 2020
@jcouv jcouv added the Feature - Nullable Reference Types Nullable Reference Types label Oct 26, 2020
{
#if REPORT_MAX
int slots = _variableSlot.Count;
if (slots > _maxSlots.Item2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Item2 [](start = 34, length = 5)

nit: name tuple elements?

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 1)

@jcouv
Copy link
Member

jcouv commented Oct 27, 2020

Just curious, what gave you an indication this was a problem to investigate in the first place?

@jcouv jcouv self-assigned this Oct 27, 2020
private SharedWalkerState SaveSharedState() =>
new SharedWalkerState(
#if REPORT_MAX
private static (Symbol, int) _maxSlots;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static should have the s_ prefix attached


private SharedWalkerState SaveSharedState() =>
new SharedWalkerState(
#if REPORT_MAX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider

#if !DEBUG
#error Need REPORT_MAX and DEBUG
#endif

(containingType is null || AccessCheck.IsSymbolAccessible(member, containingType, ref discardedUseSiteDiagnostics)))
{
int childSlot = GetOrCreateSlot(member, slot, true);
int childSlot = GetOrCreateSlot(member, slot, forceSlotEvenIfEmpty: true, createIfMissing: false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true [](start = 88, length = 4)

It feels inconsistent passing true here and false for the next argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll address in a subsequent PR.

");
c.VerifyDiagnostics(
);
// (13,17): warning CS8602: Dereference of a possibly null reference.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// (13,17): warning CS8602: Dereference of a possibly null reference. [](start = 16, length = 69)

Description of the PR sounds like a pure optimization, but there is a behavior change. Was this behavior change one of the goals of the PR, or is this just a fall out of the change that are willing to live with?

Copy link
Contributor Author

@cston cston Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of the PR was to fix the perf issue, and the behavior change here fell out of that. That said, the old behavior for this scenario doesn't seem much better than the new behavior, and not worth the cost.

@AlekseyTs
Copy link
Contributor

Done with review pass (iteration 2)

@cston cston merged commit e68926f into dotnet:master Oct 27, 2020
@cston cston deleted the GetOrCreateSlot branch October 27, 2020 15:50
@ghost ghost added this to the Next milestone Oct 27, 2020
cston added a commit to cston/roslyn that referenced this pull request Nov 19, 2020
@allisonchou allisonchou modified the milestones: Next, 16.9.P2 Nov 24, 2020
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.

7 participants