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

RyuJIT: Optimze Type.GetType("type id str") to type handle #31974

Closed
EgorBo opened this issue Feb 8, 2020 · 2 comments
Closed

RyuJIT: Optimze Type.GetType("type id str") to type handle #31974

EgorBo opened this issue Feb 8, 2020 · 2 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI optimization untriaged New issue has not been triaged by the area owner

Comments

@EgorBo
Copy link
Member

EgorBo commented Feb 8, 2020

I wonder if it makes sense in RyuJIT to optimize things like

Type type = Type.GetType("Foo.MyType"); // and, perhaps,  typeof(T).Assembly.GetType

to a runtime equivalent of :

Type type = typeof(Foo.MyType); // to CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE

Once #1378 is merged there will be getStringLiteral API for ldstr tokens.

Example: Environment.Unix.cs (on tier1 compilation most assemblies/types most likely will be already known/loaded, e.g. via the same code but on tier0 🙂)

Or this is how we detect mono runtime:

bool isMono = typeof(object).Assembly.GetType("Mono.RuntimeStructs") != null;

/cc @jkotas @MichalStrehovsky

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-TypeSystem-coreclr untriaged New issue has not been triaged by the area owner labels Feb 8, 2020
@jkotas
Copy link
Member

jkotas commented Feb 8, 2020

I do not think this optimization is useful.

Example: Environment.Unix.cs

This is one-time initialization already. This method won't ever reach tier 1.

typeof(object).Assembly.GetType("Mono.RuntimeStructs")

This is using private reflection against internal runtime implementation details. It is something to discourage, not encourage by optimizing it.

This should be fixed by having proper public APIs to detect the runtime you are running on.

@jkotas jkotas added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI optimization and removed area-TypeSystem-coreclr labels Feb 8, 2020
@EgorBo
Copy link
Member Author

EgorBo commented Feb 8, 2020

Ok, closing it then

@EgorBo EgorBo closed this as completed Feb 8, 2020
@ghost ghost added the will_lock_this label Dec 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI optimization untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants