• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by AlanGameDev · Jul 27, 2014 at 03:17 AM · androidslowmonocompilejit

How to compile function? (to prevent JIT spikes)

Hello there.

I have a game that's almost ready and it's stuttering on low-end Android devices due to JIT spikes. Whenever I call a function for the first time the game stutters but it runs smoothly on the subsequent calls.

It seems RuntimeHelper.PrepareMethod is not available in Unity and I'd like to know if there's a way to somehow compile the functions without calling them.

I'm 100% sure that the problem is the JIT compilation, not only because of the obvious symptoms but also I asked a friend to profile the scripts in a low-end Android device and he confirmed the problem is that.

Any help is appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AlanGameDev · Jul 27, 2014 at 11:09 PM

Hello guys,

I don't know if I can answer myself, but found a way to compile a function without running it, just call:

 MyFunctionToCompile.Method.MethodHandle.GetFunctionPointer();

I can confirm this works flawlessly.

Functions called in the function being compiled won't be compiled because you're not actually running it, so if you have a functionA that just calls functionB (which is slow) and does some basic math, you want to compile functionB. Well... you can always compile both in any case :).

Thanks.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Why Android doesn't support ARM64 Mono JIT? 0 Answers

Unity force stop build to Android 2 Answers

Mono.Cairo On Android 0 Answers

Conditional Compilation in middle of large script? 2 Answers

Unity Admob Lags and slows down game significantly. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges