Skip to content

Optimize code generated by Weaver using .tail prefix #367

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SergeiPavlov
Copy link
Contributor

@SergeiPavlov SergeiPavlov commented Dec 28, 2023

Assembly code generated by JIT for Entity.Field getter:

before optimization (without .tail):

push        rbp  
sub         rsp,20h  
lea         rbp,[rsp+20h]  
mov         qword ptr [rbp+10h],rcx  
mov         r8,1914C813828h  
mov         r8,qword ptr [r8]  
mov         rcx,qword ptr [rbp+10h]  
mov         rdx,7FFA24FE6D40h  
call        qword ptr [CLRStub[MethodDescPrestub]@00007FFA24FCB078 (07FFA24FCB078h)]  ; GetFieldValue<>()
nop  
add         rsp,20h  
pop         rbp  
ret 

After optimization (with .tail):

mov         r8,1F7CFC13828h  
mov         r8,qword ptr [r8]  
mov         rdx,7FFA24FE20B0h  
jmp         qword ptr [CLRStub[MethodDescPrestub]@00007FFA25001FA8 (07FFA25001FA8h)]   ; GetFieldValue<>()

The same effect for setters (SetFieldValue())

The assembly was build with enabled optimization.

The JIT itself does not always apply this kind of optimization
see https://stackoverflow.com/questions/491376/why-doesnt-net-c-optimize-for-tail-call-recursion
dotnet/csharplang#2304

* Tail prefix in weaver

* Revert version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant