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

Cache GenericTypeDefinition to improve perf #78288

Conversation

lateapexearlyspeed
Copy link
Contributor

Fix #73860

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 13, 2022
@ghost
Copy link

ghost commented Nov 13, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix #73860

Author: lateapexearlyspeed
Assignees: -
Labels:

area-System.Reflection

Milestone: -

@jkotas
Copy link
Member

jkotas commented Nov 20, 2022

I have pushed some changes:

  • Switch to dedicated field for the generic type definition. There was a non-trivial risk for activator cache and generic type definition cache to collide, and regress overall scenario performance a lot.
  • Miscellaneous performance fixes (details are in the commit descriptions). Performance numbers with these changes:
    • typeof(List<int>).GetGenericTypeDefinition() is 10x faster when the cache is hit
    • typeof(List<>).GetGenericTypeDefinition() is 3x faster when the cache is hit
    • Reflection per-type cache stores an extra pointer (grows from 152 bytes to 160 bytes on 64-bit)

@jkotas jkotas changed the title Put GenericTypeDefinition into genericCache to try to improve perf Put GenericTypeDefinition into genericCache to improve perf Nov 20, 2022
@jkotas jkotas changed the title Put GenericTypeDefinition into genericCache to improve perf Cache GenericTypeDefinition to improve perf Nov 20, 2022
@jkotas jkotas merged commit 8902a95 into dotnet:main Nov 22, 2022
@jkotas
Copy link
Member

jkotas commented Nov 22, 2022

@lateapexearlyspeed Thank you for getting this started!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Reflection community-contribution Indicates that the PR has been added by a community member tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeType.GetGenericTypeDefinition() performance issue
4 participants