Matt Whitfield
Matt Whitfield

Reputation: 6574

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?

Upvotes: 3

Views: 231

Answers (1)

vcsjones
vcsjones

Reputation: 141688

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.

Upvotes: 3

Related Questions