Farseer on MonoTouch and Mono for Android

Topics: Developer Forum
Mar 23, 2013 at 9:50 PM
I have a game project using MonoGame that runs on Windows Phone, Android and iOS. Everything is fine except that Farseer is really slow on Android and iOS.

I could probably optimize my game engine a lot, but I done all the obvious things and the game is still slow. I have also verified that the problem is with Farseer, for when I disable it my game runs at full FPS.

So I'm wondering if there are any "secret" optimizations that can be done. Either by changing compile time settings in the engine or if there are any known tricks that helps performance on Mono*.

Alternatively, I was also wondering if the latest versions in the source repository contains any of the upcoming optimizations for Mono. In that case I could try that instead.

Thanks in advance!

Mar 24, 2013 at 2:55 PM
Edited Mar 24, 2013 at 3:35 PM
Hi Rune,

Coincidentally, I've just been through this recently, I'm porting a Farseer game from WP7 (where performance is fine) to Android using MonoGame. So I can answer your question from an Android perspective, here is what I've found out:

Performance on the Android Emulator is not representative of how it'll perform on the device, as you probably know already. I only got the game running on the Android Emu by using the Intel x86 device images, using the ARM ones the game was unplayably slow. But either way the Emu tells me pretty much nothing about how it'll perform on an actual device.

I first tried my game on a Samsung Galaxy Ace, and it was running at about 0.5 fps or less. Unplayable. I believe the problem is because older Android devices have CPUs running ARM v6 instruction sets (or earlier) and this doesn't support hardware floating point. Any floating point calculations have to be done in software. Games in general, and physics engines in particular, make plenty use of floating point calculations.

I tried again with my game on a Samsung Galaxy Ace 2, and it's CPU (a NovaThor U8500) runs ARM v7. Now we get hardware floating point and the game runs beautifully at a smooth 30 fps.

If you're using MonoDevelop, you've got a project option if you look at Project Options -> Build -> Android Build -> Advanced, where you can specify what ABIs you support. If you ONLY tick ARMEABI-V7A then you're game will generate ARM v7 CPU instructions and can use hardware floating point. In addition, your game won't be visible in the Google Play marketplace to phones that cannot run that instruction set.

Edit: Since I'm planning to port to iOS sometime later, I'll be very interested to know how you get on with Farseer performance on iOS. Do let us know!
Mar 24, 2013 at 9:39 PM
I will try and see if this helps on my game as well. I have the same problem on both Android and iOS so I suspect something else must be done as well, but this is a start at least :-)
Mar 31, 2013 at 5:53 PM
Ha! I finally got it to behave on iOS. The trick was to not run XNA with fixed timesteps. This completely solved my performance problems on iOS. I haven't tried the fix on Android yet, but the two platforms have behaved similarily so far.

So, to summarize:

In the constructor of my game class I set the IsFixedTimeStep property to False. Now my game runs perfectly on iOS devices. When using fixed time steps the performance is hopeless.