-
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
System.Reflection.MetadataLoadContext performance #30886
Comments
Moving to future due to scheduling + priority. |
Moving to 9; we should at least perform some traces to see where the perf hit is; MLC does have extensive caching but perhaps there are temporary allocs that are being done based on the alloc numbers above. |
If anyone looks into this in the future, I think it's specifically iterating over methods that is slow: Someone else did a comparison, and MLC performs somewhere in between Mono.Cecil and SRM if you remove these lines in all benchmarks. |
Indeed, resolving assemblies and iterating types has excellent performance, but digging any deeper into a Modifying @jonathanpeppers test case to simply iterate type names and nothing else shows performance very close to
Benchmark code: [Benchmark (Description = "MetadataLoadContext - Types")]
public void SystemReflectionMetadataLoadContext ()
{
var resolver = new SimpleResolver (assemblies);
using (var context = new MetadataLoadContext (resolver)) {
foreach (var assemblyFile in assemblies) {
var assembly = context.LoadFromAssemblyPath (assemblyFile);
foreach (var t in assembly.GetTypes ()) {
var name = t.Name;
}
}
}
}
[Benchmark (Description = "MetadataLoadContext - Types + Nested Types")]
public void SystemReflectionMetadataLoadContext2 ()
{
var resolver = new SimpleResolver (assemblies);
using (var context = new MetadataLoadContext (resolver)) {
foreach (var assemblyFile in assemblies) {
var assembly = context.LoadFromAssemblyPath (assemblyFile);
foreach (var t in assembly.GetTypes ()) {
var name = t.Name;
foreach (var m in t.GetNestedTypes ()) {
var mname = m.Name;
}
}
}
}
} |
I have a benchmark here: https://github.com/jonathanpeppers/Benchmarks/blob/7db49fb3d272c5b07deda166dd4f5a5112258bbe/Benchmarks/Cecil.cs#L90-L111
And I am getting "not so great" results for
SR.MetadataLoadContext
:The performance compared to using raw SRM or Mono.Cecil is drastically worse.
I expected it to be somewhere in the middle of using SRM and Mono.Cecil. Is there something I'm doing here that would explain the poor performance?
Thanks!
The text was updated successfully, but these errors were encountered: