-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[WASM][AOT] Generic methods are 5000x slower than non-generic methods using profiled AOT #48163
Comments
Tagging subscribers to 'arch-wasm': @lewing Issue DetailsDescriptionRepro: https://github.com/jeromelaban/Wasm.Samples/tree/master/Bug48163/Bug48163 Consider the following code: [MethodImpl(MethodImplOptions.NoInlining)]
static int TestGeneric<T>(T value, int other)
{
for (int i = 0; i < innerCount; i++)
{
other += i;
}
return other;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static int TestNormal(int value, int other)
{
for (int i = 0; i < innerCount; i++)
{
other += i;
}
return other;
} The generic method is executing 5000x slower than the normal method (~5s vs. ~1ms), even when the profile recorded it. When using Full AOT, this same generic method is running at the same speed than the normal method. ConfigurationRegression?No. Other information
|
The reason the generic method is not AOTed comes from this line: runtime/src/mono/mono/mini/aot-compiler.c Line 12784 in 629ad50
Where no assemblies are loaded during the profile parsing, making resolutions here fail: runtime/src/mono/mono/mini/aot-compiler.c Line 12748 in 629ad50
|
I think this is critical to enable any computation-intensive library code to run with reasonable performance with profiled AOT. For example people keep trying image processing with ImageSharp in the browser, I think it would be important to make that experience at least not terrible. ImageSharp relies heavily on generics, and I assume there are other libraries which also do so. |
After investigating the issue a bit deeper, doing the following loads the assemblies and the profile gets loaded further: if (acfg->aot_opts.image_files) {
GList *l;
MonoAssembly *assembly;
printf("Loading additional image files\n");
for (l = acfg->aot_opts.image_files; l; l = l->next) {
printf("Loading additional assembly: %s\n", (char*)l->data);
assembly = mono_domain_assembly_open_internal (mono_domain_get (), mono_domain_default_alc (mono_domain_get ()), (char*)l->data);
if(!strcmp(ass->aname.name, assembly->aname.name)) {
printf("Skip loading additional main assembly: %s\n", (char*)l->data);
continue;
}
if(assembly){
printf("Loaded additional assembly: %s\n", (char*)l->data);
acfg->loaded_assemblies = g_slist_append (acfg->loaded_assemblies, assembly);
}
else{
printf("Not loaded additional assembly: %s\n", (char*)l->data);
}
}
}
else {
printf("No additional image files\n");
} then changing GSList *loaded_asm = acfg->loaded_assemblies;
printf ("acfg assemblies: %p\n", loaded_asm);
for (; loaded_asm; loaded_asm = loaded_asm->next) {
MonoAssembly *ass = loaded_asm->data;
if (!strcmp (ass->aname.name, idata->name)) {
idata->image = ass->image;
break;
}
} but even though loading the makes the resolution go further, deduping goes in the way and generic methods get excluded here: runtime/src/mono/mono/mini/aot-compiler.c Line 4243 in d5ab93c
|
Just for clarity, does this result apply with no profile? |
Without a profile, the generic methods are AOTed properly, and the performance for both generic and non-generic method is similar. |
This should be fixed now. The fix might cause issues to surface in other places. |
Description
Repro: https://github.com/jeromelaban/Wasm.Samples/tree/master/Bug48163/Bug48163
Consider the following code:
The generic method is executing 5000x slower than the normal method (~5s vs. ~1ms), even when the profile recorded it.
When using Full AOT, this same generic method is running at the same speed than the normal method.
Additionally, with a similar benchmark, using
Dictionary<,>
:Dictionary<int,int>.TryGetValue()
Mixed: 00:00:00.0385150, FullAOT: 00:00:00.0347Dictionary<string,string>.TryGetValue()
Mixed: 00:00:00.04405, FullAOT: 00:00:00.0090600Configuration
bb65067
Regression?
No.
Other information
The text was updated successfully, but these errors were encountered: