-
Notifications
You must be signed in to change notification settings - Fork 934
Improve performance of ReflectHelper.GetMethod/Definition #2352
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
Conversation
What is the performance improvement? :) Old way seems more convenient to use... Mabye |
It is about 3-3.5 times faster (obviously it is in nanosecond ;-)) (Source) BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.2 (19C57) [Darwin 19.2.0]
Intel Core i5-4308U CPU 2.80GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=3.1.200
[Host] : .NET Core 3.1.2 (CoreCLR 4.700.20.6602, CoreFX 4.700.20.6702), X64 RyuJIT
DefaultJob : .NET Core 3.1.2 (CoreCLR 4.700.20.6602, CoreFX 4.700.20.6702), X64 RyuJIT
BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.2 (19C57) [Darwin 19.2.0]
Intel Core i5-4308U CPU 2.80GHz (Haswell), 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=3.1.200
[Host] : .NET Core 2.1.16 (CoreCLR 4.6.28516.03, CoreFX 4.6.28516.10), X64 RyuJIT
DefaultJob : .NET Core 2.1.16 (CoreCLR 4.6.28516.03, CoreFX 4.6.28516.10), X64 RyuJIT
EDIT: (3.1 results were outdated) |
For me it's about the same.
I thought on naming it like this, but I like FastGetMethod as it feels more natural. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though it seems it's really useful only in one place for WithLock
extension (should we also move it to static field?). And other places are executed only once. But why not...
Actually, with FastGetMethod we might not need the static fields anymore to hold methods. |
Usage of ReflectHelper.GetMethod requires a runtime construction of a lambda expression and later deconstruction of it.
The decompiled code of old GetMethod
The idea of a new method is that we utilize the creation of the delegate from a method group and later use delegate's
.Method
property.The decompiled code of FastGetMethod