I’m exploring the use of RuntimeHelpers.PrepareMethod() to reduce start-up time on thin client applications with heavy UI libraries
I created a JIT-helper class to run on a background thread and iterates through methods of a type or assembly and calls PrepareMethod on them
First of all, is there any drawback to doing this? (and I don’t mean JIT-ing the entire application, I mean just heavy libraries eg Infragistics, DevExpress and classes representing window classes in WPF)
Secondly, is there anyway to determine whether or not a method has been JIT-ed already? (although I didn’t notice any delay or problems from accidentally calling it multiple times)
Lastly, what happens if I do the JIT-ing on a background thread and another thread calls a method that is currently being JIT-ed?
Since what you ask is highly implementation-dependent there is no definitive answer… I would expect there to be some sort of locking on the method while it is being JITted… but other than digging deep into the specific .NET version etc. this remains speculation…
BTW: there is a (non-public) field called
IsJittedon the respectiveMethodDescwhich the JIT compiler sets totrueafter jitting… for some more information see here…