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

Possible to detect AOT mode during runtime? #76739

Closed
sengiv opened this issue Oct 7, 2022 · 6 comments
Closed

Possible to detect AOT mode during runtime? #76739

sengiv opened this issue Oct 7, 2022 · 6 comments
Labels
area-Codegen-AOT-mono question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@sengiv
Copy link

sengiv commented Oct 7, 2022

This can be helpful when doing A/B testing or when showing AOT version of the app only to desktop users.

For example, we are using Azure CDN to mask 2 versions of the same app,
mobile users get the normal Blazor & desktop users get the AOT version.
With the same domain name.

The obvious solution is to set a flag during the build process of the AOT version.
And this is the direction we are heading.

But is there another straightforward way?

@javiercn javiercn transferred this issue from dotnet/aspnetcore Oct 7, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 7, 2022
@huoyaoyuan
Copy link
Member

Is RuntimeFeature.IsDynamicCodeCompiled sufficient?

@marek-safar marek-safar added the question Answer questions and provide assistance, not an issue with source code or documentation. label Oct 7, 2022
@Suchiman
Copy link
Contributor

Suchiman commented Oct 7, 2022

@hez2010
Copy link
Contributor

hez2010 commented Oct 7, 2022

The BenchmarkDotNet trick is incorrect because PublishSingleFile also produces null for Assembly.Location.
IMO the correct way should be using RuntimeFeature.IsDynamicCodeCompiled.

@sengiv
Copy link
Author

sengiv commented Oct 8, 2022

@huoyaoyuan

Is RuntimeFeature.IsDynamicCodeCompiled sufficient?

After multiple tests, this does not work (tried in .NET 6 & .NET 7)

I tried the line below just before await webAssemblyHost.RunAsync();
Console.WriteLine(RuntimeFeature.IsDynamicCodeCompiled?"AOT MODE":"NORMAL MODE");
Unfortunately, it only returns false both in AOT and Interpreted.

@hez2010
Copy link
Contributor

hez2010 commented Oct 8, 2022

How about RuntimeFeature.IsDynamicCodeSupported?

Mode IsDynamicCodeSupported IsDynamicCodeCompiled
JIT True True
Interpret True False
AOT False False

@sengiv
Copy link
Author

sengiv commented Oct 8, 2022

How about RuntimeFeature.IsDynamicCodeSupported?

Mode IsDynamicCodeSupported IsDynamicCodeCompiled
JIT True True
Interpret True False
AOT False False

Thanks a lot @hez2010, RuntimeFeature.IsDynamicCodeSupported is working perfectly.
Tested working in .NET 7

@sengiv sengiv closed this as completed Oct 8, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-AOT-mono question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

5 participants