Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cause code to be pre-JITted at run time without using PrepareMethod

I need to cause some code in my application to be pre-JITted. The scenario is an XNA game running under Windows Phone. When an explosion first happens, there is a noticeable pause while the methods that implement the explosion physical modelling are JITted. I know this because this issue happens on the Windows build as well, and disappears when the assemblies are NGEN'd. I have also used the method of JITting at runtime which is mentioned in a few answers here and originates on CodeProject (using reflection and PrepareMethod) .

However, I can't use NGEN, because it's a Windows Phone app. I also can't use the other method PrepareMethod is marked as SecurityCritical, and you can't call that on Windows Phone.

I don't mind the fact that it may take some time, because the initialisation would happen on a separate thread while a loading screen is displayed.

Are there any elegant methods to achieve a similar result and, failing that, any methods at all?

like image 220
Matt Whitfield Avatar asked Apr 13 '26 01:04

Matt Whitfield


1 Answers

In Windows Phone as of now, the only thing you can do is force the method to be JITed is by actually calling it.

I would call the method while your application is loading, perhaps while it is showing a load screen or something. That way when the user actually hits it during the game, the JIT has already been taken care of.

like image 82
vcsjones Avatar answered Apr 15 '26 14:04

vcsjones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!