Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6179047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:34:45+00:00 2026-05-24T00:34:45+00:00

This is a question I probably should have asked sooner but didn’t in my

  • 0

This is a question I probably should have asked sooner but didn’t in my rush to have fun with p/invoke type stuff in MonoTouch.

Basically I have a problem with performance pertaining to a very large number of floating point operations, specifically ones involving min/max functions, vector multiplication and simlar stuff (basically detecting if different kinds of shapes are intersecting or not).

The reason for these operations is because of a 2D physics engine written in C#.

On some platforms such as Windows Phone 7 and the Xbox 360 the physics engine runs without any hitches, it steals some CPU cycles but leaves plenty to ensure the game is running at a steady framerate.

The problem is in MonoTouch running on the iPhone. It appears MonoToch is not all that great with so many floating point operations and the iPhone (and EVEN the iPad 2) finds itself being severely impacted and physics being the obvious performance bottleneck. I’ve profiled the performance and it comes down to a set of relatively basic math functions as I mentioned before and there’s no real way of optimizing those functions, the physics engine itself is very well written and I can’t see any obvious place it’s lagging in and frankly I doubt there’s anything wrong with it as a 2D C# physics engine.

To that end I’ve resolved to find a physics engine written in C (or C++ if possible) and hook it up with the main MonoTouch application. My reasoning is that since the performance issues in MonoTouch probably have something to do with the fact the MonoTouch compiler does not compile .net code to run as fast as the Wp7/xbox 360 JIT compilers do (which is understandable) moving things out of monotouch and running them natively would help improve performance.

So my idea is that I’ll use Box2D, write a bunch of static wrapper functions (such as CreateWorld(), CreateBox(), GetBodyPosition(int id), etc, etc) and hook all that in via p/invoke functionality and integrate it all into my physics wrapper class, in this way the core game logic will require minimal to no modifications and I can maintain the integrity of the original code design but also gain performance boosts due to the fact the physics is running in native C.

But this got me thinking, the performance issues are stemming from very simple and straightforward mathematical functions, simple multiplications and size comparisons. If running functions via p/invoke wiould improve speed then simply re-writing a function such as Vector2.Max as a C function and invoking that also improve performance?

This however seems a bit farfetched, if it was the case wouldn’t Mono do that anyway?

So I guess my overall question is, do statically linked native libraries perform better when called from p/invoke than the equivalent C# function compiled by MonoTouch?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:34:47+00:00Added an answer on May 24, 2026 at 12:34 am

    There is really only one way to figure out if it’s faster: benchmark your case. It might be that the c compiler you’d use for the native library is able to optimize more than what mono’s jit does, or it might be just the cpu which isn’t suited well for your particular workload.

    If you want to try out using a native library, have in mind that you do not want to call native code from managed often, there is a significant performance hit for each managed to native transition (how significant depends on a lot of factors, but fewer transitions is always better).

    That said, my personal guess would be that the mono jit doesn’t handle floating point operations as well as it could (there have been issues with this before on some cpus, I don’t remember now if those issues still exist nor on which cpus), so you would benefit from using a native library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this question has probably been asked numerous times, but I have not
This is probably the simplest question ever asked, but if I have a running
Probably this question was already asked before, but my google-fu and SO-Search did not
This question is related to this one but I think should be asked separately.
At first, I know this question probably exists, but on first sight I didn't
This question may seem daft (I'm a new to 'programming' and should probably stop
This is one of those I probably should know this, but I don't questions.
Ok, so this question probably isn't Silverlight specific. I have a silverlight 2 page
I know this question is probably stoopid. But I just don't want to cause
This is confusing me, so this question will probably be confusing. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.