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

Use LinkContext caching when resolving ExportedTypes #3075

Merged
merged 5 commits into from
Oct 20, 2022

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Oct 18, 2022

When profiling ASP.Net benchmark builds, I found significant time was being spent resolving ExportedType
's since we don't have a cache for those like we do for TypeReference and MethodReference.

Bans MethodReference.Resolve and ExportedType.Resolve and recommend LinkContext.Resolve instead (except in SweepStep).

Adds a cache on LinkContext for resolving ExportedTypes and replaces calls to Cecil's Resolve.

Replaces some calls to MethodReference.Resolve.

Together with #3073, performance improves to better than before the virtual method regression in August.

Trimmer CPU milliseconds on ASP.Net benchmarks build:
27325 before the regression related to #3067
87310 in main
23520 after #3073 + this change

src/linker/Linker.Steps/SweepStep.cs Outdated Show resolved Hide resolved
@@ -10,6 +10,7 @@ namespace Mono.Linker
{
public static class MethodReferenceExtensions
{
[System.Diagnostics.CodeAnalysis.SuppressMessage ("ApiDesign", "RS0030:Do not used banned APIs", Justification = "MethodReference.Resolve is banned for performance reasons. GetDisplayName should be a really cold path and shouldn't require a context to call.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Please use pragma
  • Would it be too ugly to pass the context to GetDisplayName?

Copy link
Member Author

Choose a reason for hiding this comment

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

It might not necessarily be ugly, but I think it would take significant effort to bubble up the context parameter to GetDisplayName on all the SingleValue types and TypeSystemProxy types, and it's really only called from diagnostics which should be a very cold path anyway.

src/linker/Linker.Steps/SweepStep.cs Outdated Show resolved Hide resolved
src/linker/Linker.Steps/SweepStep.cs Show resolved Hide resolved
Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@marek-safar marek-safar merged commit add4655 into dotnet:main Oct 20, 2022
jtschuster added a commit to jtschuster/linker that referenced this pull request Oct 21, 2022
tlakollo pushed a commit to tlakollo/runtime that referenced this pull request Oct 27, 2022
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants