Skip to content

Optimize code generated by Weaver using .tail prefix #156

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

Merged
merged 2 commits into from
Nov 7, 2023

Conversation

SergeiPavlov
Copy link
Collaborator

@SergeiPavlov SergeiPavlov commented Nov 4, 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 apply this kind of optimization
see https://stackoverflow.com/questions/491376/why-doesnt-net-c-optimize-for-tail-call-recursion
dotnet/csharplang#2304

@SergeiPavlov SergeiPavlov merged commit ae46f6e into master-servicetitan Nov 7, 2023
@SergeiPavlov SergeiPavlov deleted the weaverTail branch November 7, 2023 00:44
SergeiPavlov added a commit that referenced this pull request Dec 28, 2023
* 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.

2 participants