Mono Performance For Games

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
I've become a huge fan of C#. I truly love the language. I picked it up to use XNA and play with making Windows applications, but I want to bring that experience to OS X. I know about Mono and have been playing with it. I have yet to use Cocoa#, the C# bindings for Cocoa, but overall it's nice.

My question though is how capable it is as a runtime. I've heard some people say that Mono's .NET implementation is too slow to do any real game programming. I was just wondering if anyone here has any more experience with Mono and could comment on it. I plan to use SdlDotNet and Tao.OpenGL for my windowing and graphics, respectively.

Just looking for opinions or statistics or anything relevant. Thanks in advance.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
I use C# inside unity. As they've done most of the hardwork, only my game logic code is in C#, and it is more than fast enough.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #3
I did notice Unity uses it and I believe they even use Mono for the CLR and JIT (if I read correctly). But Unity probably also has a large C/C++/Objective-C (one of them) underlying engine to implement the intensive parts.

I'd like to try and create an entire OpenGL game in C# using Mono. Granted right now I just want 2D, but I'm trying to figure out if it's even going to be powerful enough to make a nice 2D game without showing lots of performance issues.
Quote this message in a reply
Oldtimer
Posts: 832
Joined: 2002.09
Post: #4
Only AAA games are CPU-bound nowadays anyway, so I say go for it. It can't reasoably be much slower than Rosetta emulation, and that works for a lot of games. Smile
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #5
I picked up C# through XNA as well. I'd say it's definitely worth exploring!
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #6
It's very fast. I'd wildly guess only 2-10 times slower than C.

Inside Unity, I do a lot of things in C# (or their JavaScript... which would more accurately be called UnityScript) that you would normally think insane to do in a language like that, but it almost always turns out very fast and I hardly ever have to farm it out to a C/C++ plugin. Things like generating textures, automatically generating texture atlases from models that use multiple textures, A* pathfinding with lots of nodes. The only thing computationally intensive I've ever farmed out to a C/C++ plugin was the beef of the computations in a computer vision program.

So another point, is that it's actually really easy to have your C# call C/C++, and the reverse. This page is the bible for that:
http://www.mono-project.com/Interop_with..._Libraries

So rarely, when something is too slow, you can just rewrite it in C/C++/Obj-C/Whatever.

Cheers,
-Jon
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #7
Nick Wrote:I did notice Unity uses it and I believe they even use Mono for the CLR and JIT (if I read correctly). But Unity probably also has a large C/C++/Objective-C (one of them) underlying engine to implement the intensive parts.

I'd like to try and create an entire OpenGL game in C# using Mono. Granted right now I just want 2D, but I'm trying to figure out if it's even going to be powerful enough to make a nice 2D game without showing lots of performance issues.
That's correct with regards to Unity, and you should be able to. And if it is turning out slowly, see my last post about interoperating with native libraries.

-Jon
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #8
Do you know of resources showing how to interoperate with Objective-C? I can see how C# would work with C and C++, but how do I go about doing it with Objective-C? I'm thinking I could just use the GameBaseFramework for my windowing and leave C# to just the gameplay and graphics, but I have no idea where to start.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #9
Unfortunately you have to have C callable wrappers that call the Obj-C.

-Jon
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
http://shootout.alioth.debian.org/gp4/be...l&lang=all

Note that there is a distinct set of "fast" language implementations at the top of the list (up to about 3x slower than C) and then a distinct set of "slow" language implementations at the bottom (9-64x slower than C).

Mono is distinctly in the top section. That means it's good for like 99% of your game code, though you might still have to drop into C for some really performance-intensive bits.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #11
Wow, I didn't realize Lua would be *that* much slower than Mono C#. That makes me seriously interested in ditching Lua for Mono if I could swing it. I would rather use C# any day over Lua (or anything else except obj-c for that matter!), but I wonder about the size. Surely one would only need to include a small subset of Mono, like maybe a basic runtime, but I really don't know anything about Mono's components. Taking a wild guess that the runtime and compiler might be in the mono binary (in the mono framework/bin), that would still be 11.2 MB, which is far more than Lua's ~550k.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
The minimal size for a Unity UB used to be in excess of 20MB... I think they may have managed to reduce it since then though... perhaps a Unity user can comment Wink
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #13
I was able to use Mono's macpack utility to package up an app bundle with the Mono libraries included and it totaled about 9mb. So it's definitely a larger app than a native C one, but with today's internet speeds, it's nothing I'm particularly worried with. The art assets are bound to outweigh the library size.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #14
Still, if your app is only 20 MB including Mono, it kinda stinks to be paying for half of your bandwidth just because of it. Bandwidth is cheap, sure, but it ain't free, especially for indie or hobby projects. I hate to think I'd spend a lot of effort compressing images and assets and stuff into a 10 MB footprint, only to lose all that ground to Mono. Lua is so small that it could be considered just another image asset, not to mention great performance and familiarity, with only a relatively small price to pay in the funky syntax and non-easy-oop department. But C#'s usability, syntax and performance blows away pretty much everything that runs in a VM IMHO. I dunno, maybe 10 MB is a good space to budget for C# if that can be done. Tough call! I guess I need to start looking more seriously at it.

Well anyway, if you figure anything more out about it I'd be interested to hear!Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #15
Is your 9MB Mono app package a UB? Is that a compressed measure or an uncompressed measure?
Quote this message in a reply
Post Reply