Jump to content

C++ vs C# Performance


photo

Recommended Posts

  • 1 year later...

Sorry for digging up such an old thread but I just ran the examples with the latest engine version and it's pretty much on par using that Images sample. C++ seems to be up to 2-3% faster here on my machine.

 

  • Like 2
Link to comment
  • 2 years later...

Hi,

actually, UNIGINE are wrapping their C++ classes to managed .NET-plattform as far as I am aware of. There is a struct called "HandleRef", which wraps a managed object while holding an resource that is passed to unmanaged code (C++). All UNIGINE main objects (Body, Camera, Nodes) in C# uses those HandleRef to get access to the main C++-Api. 

So for your question: there is a little bit of overhead comparing to native C++-implementation but this should be "negligible" and is not easy to answer. I can advice the book "Expert Visual C++/CLI: .NET for Visual C++ Programmers" that have multiple chapters about wrapping and how they work. Also, with the last mayor engine release UNIGINE introduced an C# math API which should improve performane as well.

My personal opinion: Maybe consider first what you want to achieve in your project and which language is working best for you. In our last project we switched from C++ to C#-environment because we got easier access to other libraries such as QR-reading, network replication and security features (like file/stream encryption/decryption) which was way faster to achieve on C#.

Link to comment

So in short, Unigine managed code is not compiled into native code, so performance could be compared to Unity GameObjects (skipping the fact that those are MonoBehaviours at this point). I am just researching at this point, but it looks that Unity DOTS should perform much better in case of using C#. I though that C++ should give a performance boost and allow me to migrate from messy Unity.

Link to comment
3 hours ago, nitrooo said:

So in short, Unigine managed code is not compiled into native code, so performance could be compared to Unity GameObjects (skipping the fact that those are MonoBehaviours at this point).

Yes, and no. As far as I remembered, Unity3D is also written natively in C++ and in it's core it is mainly driven by a main thread because of design choices years ago. On top of that you have the Mono scripting language, which uses an just-in-time-compilation (JIT), but that feature isn't available on every plattform.

To get rid of those limitations, IL2CPP was implemented as second choice to support a wider range of plattforms and easier access to an multi-threaded environment (So you can use the Task-classes and Task.Run() in C# but with limitations [see below]). However, those IL2CPP has still limitations on their own by design (you can have a look here for Unity3D). IL2CPP backend converts MSIL (Microsoft Intermediate Language) code (for example, C# code in scripts) into C++ code, then uses the C++ code to create a native binary file (.exe) for execution. So yes, because of those conversions the code will run as fast as in C++, while UNIGINE-Wrapper will have some overload during code execution.

BUT

As said, those wrapper-overload is "near zero" with only a couple of CPU cycles on top of native execution. The main benefit of UNIGINE (and Unreal Engine 4 and 5) is, that it was build for an multi-threaded execution on their internals on purpose! Take a look here: In this screenshot the engine will update their nodes on up to 8 cores simultaniously using as much performance as possible. Also, the new LandscapeSystem allows you to make terrain intersection and data fetching in an thread-safe environment. While not all objects are thread-safe by default, there are a lot. Unity on the other side: Is not thread safe at all. Running any functions in C# in Unity3D via async and Task.run() may work for your code, but you can't access any Unity-managed data? Create new meshes asynchronously: Use the Job System with some additional overhead of synchronisation? Even get access to the projects data folder via AppData: Forget it! So your well written C#-project in UNIGINE with usage of those multi-threaded features will (in my opinion) always runs better than any IL2CPP-Unity3D project, even with the wrapper functionality. So as always, it is up to the programmer to build an architecture for their project, which benefits of all engine advantages.

4 hours ago, nitrooo said:

I though that C++ should give a performance boost and allow me to migrate from messy Unity.

If you are even familiar with C++-code and you wan't to write an heavily optimized code, than go for it. But also here: Heavily optimizations may take a lot of time and might not worth it than spending your developement on new features.

  • Like 1
Link to comment

I am good at C++ and C#. I rejected Unreal Engine because of bloated code and blueprints. I am developing my project in Unity and I faced  poor performance of GameObjects, level streaming and some other things. While waiting for the DOTS to come out from preview stage,  just wanted to to do some research about other engines, because Unity is getting on my nerves. Unigine looks promising. Thanks.

Link to comment
×
×
  • Create New...