azist / azos

A to Z Sky Operating System / Microservice Chassis Framework
MIT License
213 stars 29 forks source link

Examine the benefit of `Internal.Runtime.CompilerServices.Undafe.As<T>(obj)` instead of `(T)obj` regular cast in tight code paths #842

Open itadapter opened 1 year ago

itadapter commented 1 year ago

https://www.tabsoverspaces.com/233888-what-is-the-cost-of-casting-in-net-csharp Unsafe:

mov       rax,rdx    
ret   

Safe:

sub       rsp,28
mov       rcx,offset MT_System.Runtime.CompilerServices.ITuple
call      CORINFO_HELP_CHKCASTINTERFACE
nop
add       rsp,28
ret

2 ns per call.....