-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Using AggressiveInlining for generated mapping methods #1381
Comments
By the way, I updated my .NET Mappers Benchmark and wanted to share it with you @latonz |
AggressiveInlining
for generated mapping methods
AggressiveInlining
for generated mapping methods
Thanks for the benchmark and the PR contribution. The performance improvements on the struct methods are impressive 😮👍 . I'm still not sure if applying aggressive inlining to all mapping methods is the best option. We should probably discuss this in more detail... My initial thoughts:
What do you think? |
I agree it needs to be discussed more. After a lot of research, the disadvantages that I'm aware and sure of, are:
One thing that I read somewhere (not in docs/reference) but I'm not sure about:
There is another thing that is worth mentioning:
The only main advise that I have seen many places: The .NET JIT compiler is designed to make intelligent inlining decisions. Trust it to handle the majority of inlining decisions, only use AggressiveInlining when you have clear evidence it will benefit performance. About your questions:
Yes, duplicate calls can leads to increased the size of the assembly, but on the otherside in a large object hierarchy with many nested mapping, using
The compiler is smart to identify most of the qualified methods for inlining but not smart enough to identify all (otherwise, it should not exist at all).
No there is not difference between static and instance mapper classes.
As you mentioned, it does not apply to nested methods, so we lose the main avantage of it (eliminating the cost of method calls) As a conclusion I thinks it's worth to experiment this feature in real large projects within community and get feedback from them. So we can release this feature as a preview version of library to get feedbacks. Thanks for bringing up various points to discuss, I'm looking forward to hearing your opinions and moving this discuss further. |
Thank you for your research! My conclusion is this: I think it makes sense to implement it, but I think we need to think about the following:
The main branch targets Mapperly 4.0 (major with breaking changes), so right now would be a good time to implement this 😊 |
Thanks for your good points! and sorry for my late resposding :)
I know your concern about the feature of this featuer but exposing an Enum property is not a good choies IMO. I thinks it's better to keep it simple (KISS principle) like a
Why not emitting both user specified values and our disered value?
We can add AggressiveInlining only if it's not already existed to prevent duplicaion.
Very good! so if you agree with any of these please let me know so I can help with the implementation. |
My thoughts:
public class MapperAttribute
{
+ public AggressiveInliningTypes AggressiveInliningTypes { get; set; } = AggressiveInliningTypes.All;
}
+ public enum AggressiveInliningTypes
+ {
+ None = 0,
+ ValueTypes = 1 << 0,
+ ReferenceTypes = 1 << 1,
+ All = ~None,
+ } Isn't this
How would overriding work with partial methods? If the user already defines the attribute on the partial definition (e.g. as Would be happy to review an implementation PR 😊 |
@mjebrahimi are you still interested in implementing this? 😊 |
Hi @latonz, sorry for the late response, I was on vacation. And thanks for waiting :) I updated the code for PR #1384 (comment) according to our discussion. |
I hope you had a wonderful vacation and thanks for the updates 😊 |
According to this benchmark, it shows using
[MethodImpl(MethodImplOptions.AggressiveInlining)]
for mappingstruct
s is much faster than not using it.I must confess that much performance difference was surprising to me but in fact, it is! and why don't we advantage of it? :)
The generated mapping methods are simple and seem safe to use with
AggressiveInlining
, so I think there's nothing wrong with it (at least it's worth a try).Note: mapping methods in this benchmark are mapperly-generated and I just edited them to decorate with
AggressiveInlining
.The text was updated successfully, but these errors were encountered: