-
Notifications
You must be signed in to change notification settings - Fork 6
Use .tail
prefix to optimize JIT-generated code
#13
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
LazyProxy/LazyProxyBuilder.cs
Outdated
@@ -235,6 +235,7 @@ private static TypeBuilder AddMethods(this TypeBuilder typeBuilder, Type type, F | |||
generator.Emit(OpCodes.Ldarg, i); | |||
} | |||
|
|||
generator.Emit(OpCodes.Tail); |
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.
Just wondering, why is the difference with OpCodes.Tailcall? (I could't find any info about OpCodes.Tail
in the docs).
And also, does this optimization work for all calls or for the recursion calls only?
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.
Ah, OpCodes.Tailcall
is correct vor .NET (fixed the code)
And .Tail
is for Cecil
library used in DO
It works only before sequence call
, ret
And this is not always recursive
I have already applied such change before and then reverted it c67bd84
My new understanding based on Debugger & StackTraces from dumps is:
Without .tail
prefix the JIT optimizer SOMETIME can guess to do it, but not in 100% cases.
tail.
prefix guarantees this kind of optimization
I cannot estimate how much this change may affect the reliability of the application. As noted in the article, this optimization is not used by default. This means that the behavior of the JIT compiler may not be sufficiently tested. Also I afraid of increased JIT time because of optimization. |
Looks like no potential flaw. This prefix is actively used by functional-language compilers like |
The effect is shown here:
servicetitan/dataobjects-net#156