Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Cross-Platform Runtime Performance

Discussion in 'Editor & General Support' started by Deleted User, Aug 6, 2014.

  1. Deleted User

    Deleted User

    Guest

    Hi,

    Either my Googling is rather ineffective, or I'm asking the wrong question. As a programmer, I am used to compiling code to a platform, and those languages that compile to multiple platforms tend to run within a virtual environment utilising managed garbage collection.

    A general rule is usually, the more generic code gets, the higher the running cost of such code. Native code will always have a performance gain over managed code due to the tighter integration with the underlying system operations, but modern day hardware and virtual environments have improved drastically that most non-performance intensive applications can happily work with managed solutions.

    Ignoring any arguments around performance of "objects in memory" management within said virtual environments, I am interested in finding out just what the performance impact of Unity is when run on multiple platforms.

    I see multiple technologies and languages being used to build Unity games, for example writing C# scripts against Mono.Net. What I'm puzzled about is how that then builds to a game on Android, iOS, or PlayStation, for which neither language nor runtime was intended.

    I can only think either it is relying heavily upon virtual machines to run common code between platforms, or some fiendishly complicated (and potentially platform-specific bug creating) compile-time transformations of the source and/or byte code to the necessary machine code for the specific platforms.

    I guess I'm wondering where the sacrifice is, and what the pros and cons are around it.

    So, my question: Compared to an engine specifically compiled for the platform, how does Unity perform across platforms? Does it consume more memory or CPU time? Is it lightweight when run on mobile devices? What advantage, if any, is gained by utilising a more native engine?

    Regards,
    Rob.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Mono runs fine on any platform that they ported it to. There's no such thing as a language "not being intended" for a given platform. It's irrelevant since it all gets compiled to the same bytecode anyway. I'm also not sure why you'd suggest that Mono is "not intended" for Android, iOS, etc.

    --Eric
     
  3. Deleted User

    Deleted User

    Guest

    Hi,

    Thanks, you've indirectly answered my question, along with the posts from joncham on this thread here.

    The answer appears to be that the bytecode gets converted at build time, and even Unity team appears to admit the conversion is not 100% accurate, so the "risks" of using Unity are broadly where I expected it to be.

    "not intended" means it isn't, mono.net started life as a means to port the .NET runtime (intended for Windows environments only, not all the ones Unity supports) across to Linux. Since then projects such as Xamarin have expanded mono.net to port to other platforms such as Android (natively Java) and iOS (natively Objective-C) where the bytecode run in those environments are not the same bytecode as that of .NET. To run code compiled against mono.net on those platforms, you have to have the mono.net virtual machine available on the system to run the .NET bytecode on a system that would not normally have a native runtime environment for it.

    Edit: Just found a much better diagram explaining virtual runtime on Android. Also, "natively" is probably the wrong word for Java, as its a VM on top of a native system.

    Regards,
    Rob.
     
    Last edited by a moderator: Aug 9, 2014
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    No...Unity 5 isn't out so the technology referred to is not used yet. Also, what they said was "While we don't expect 100% code compatibility" with IL2CPP, not that the conversion isn't 100% accurate. This refers to existing Unity code. You can read about IL2CPP here, but note again that it's not available and won't necessarily be used for all platforms when it is.

    It's not "natively Objective-C". Objective-C is the traditional source code language that is used by Apple and many developers, but you're free to use any language and everything is compiled to machine code in the end. Not bytecode. Also note that Apple is promoting Swift as their new preferred language. Unity isn't "compiled to Java" on Android, either.

    --Eric