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

Drop roslyn impact on scrolling perf by 30% #73648

Merged
merged 8 commits into from
May 22, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented May 22, 2024

Takes us from:

image

to

image

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 22, 2024 21:00
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 22, 2024
@@ -1198,7 +1198,7 @@ public void Sort(Comparison<T> comparison)

if (_size > 1)
{
SegmentedArray.Sort<T>(_items, 0, _size, Comparer<T>.Create(comparison));
SegmentedArray.Sort(_items, 0, _size, comparison);
Copy link
Member Author

Choose a reason for hiding this comment

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

existing codepath forced an allocation from comparison to comparer. That comparer was later converted back to a comparison by grabbing off the .Compare method from it. So this double allocated going through this path.

THe path that takes an IComparer single-allocs (tearing off the .Compare delegate).

Now, there is at least no alloc if passing in a comparison delegate. we pass it through all the way to the final place that uses it.

Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi May 22, 2024

Choose a reason for hiding this comment

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

Allocations caused by this contributed to nearly half of the excess costs here (as well as a ton of garbage):

image

@@ -394,6 +394,22 @@ public static void Sort<T>(SegmentedArray<T> array, int index, int length, IComp
}
}

public static void Sort<T>(SegmentedArray<T> array, int index, int length, Comparison<T> comparison)
Copy link
Member Author

Choose a reason for hiding this comment

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

copy of method above, just taking and passing through a Comparison instead of an IComparer. See https://github.com/dotnet/roslyn/pull/73648/files#r1610644205 for more details.

Copy link
Member

@sharwell sharwell May 28, 2024

Choose a reason for hiding this comment

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

To better match the reference implementation (from dotnet/runtime), let's remove this method and inline these two lines to the caller:

var segment = new SegmentedArraySegment<T>(array, index, length);
SegmentedArraySortHelper<T>.Sort(segment, comparison);

@@ -90,7 +90,7 @@ public IEnumerable<ITagSpan<IClassificationTag>> GetTags(NormalizedSnapshotSpanC
}

private static IEnumerable<ITagSpan<IClassificationTag>> GetIntersectingTags(NormalizedSnapshotSpanCollection spans, TagSpanIntervalTree<IClassificationTag> cachedTags)
=> SegmentedListPool<ITagSpan<IClassificationTag>>.ComputeList(
=> SegmentedListPool<TagSpan<IClassificationTag>>.ComputeList(
Copy link
Member Author

Choose a reason for hiding this comment

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

switched everything to be TagSpan based. Avoids lots and lots and lots and lots of virtual dispatch. Everything is non-virtual on the impl type, allowing for major inlining.

@CyrusNajmabadi
Copy link
Member Author

@sharwell for eyes on the Segmented collections part.

@CyrusNajmabadi CyrusNajmabadi requested a review from ToddGrun May 22, 2024 21:05
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun ptal.

@CyrusNajmabadi CyrusNajmabadi changed the title Drop roslyn impact on scrolling perf by 12% Drop roslyn impact on scrolling perf by 30% May 22, 2024
@@ -192,8 +194,7 @@ public async Task AddSyntacticClassificationsAsync(Document document, ImmutableA
if (root is null)
return;

var classificationService = services.GetLanguageServices(root.Language).GetRequiredService<ISyntaxClassificationService>();
Copy link
Member Author

Choose a reason for hiding this comment

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

service-retrieval continues to be surprising expensive when done in hot spots. here we can trivially lift this out such that thsi value is provided in the constructor.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@CyrusNajmabadi CyrusNajmabadi enabled auto-merge May 22, 2024 22:10
@CyrusNajmabadi CyrusNajmabadi merged commit d89c824 into dotnet:main May 22, 2024
28 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 22, 2024
@CyrusNajmabadi CyrusNajmabadi deleted the classificationPerf branch May 23, 2024 00:17
sharwell added a commit to sharwell/roslyn that referenced this pull request May 28, 2024
Remove an overload from SegmentedArray that does not have a
corresponding method in System.Array in favor of directly interacting
with SegmentedArraySortHelper.

Addresses feedback in dotnet#73648
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants