5 ms·
C# is very fast on average, but due to its runtime/GC it won't give you the consistent performance you need for game engine internals, which is what they meant
by gary_0 5y ago
C# is very fast on average, but due to its runtime/GC it won't give you the consistent performance you need for game engine internals, which is what they meant by "slow".
- pjmlp 5y agoUnless we are talking about Assembly, all languages have runtimes. As for the GC, it can be turned on in critical code paths, C# supports manual and stack memory allocation. Profilers exist, many console games have been shipped in C#, besides Unity, there are Xenko, FNA and MonoGame custom builds for game consoles. Compare the demo on the blog with, https://store.steampowered.com/app/236090/Dust_An_Elysian_Tail https://store.steampowered.com/app/236090/Dust_An_Elysian_Ta... https://store.steampowered.com/app/985890/Streets_of_Rage_4 https://store.steampowered.com/app/985890/Streets_of_Rage_4 https://store.steampowered.com/app/107100/Bastion https://store.steampowered.com/app/107100/Bastion https://www.pcgames.de/Arena-Wars-Spiel-18141/Tests/Arena-Wars-329308 https://www.pcgames.de/Arena-Wars-Spiel-18141/Tests/Arena-Wa... All of them done in regular C#, not even taking into account Unity and its DOTS/Burst C# subset.
- gary_0 5y ago> Unless we are talking about Assembly, all languages have runtimes. My point was that some languages have heavier runtimes than others (out of the box, at least). And yes, C# is very popular for gameplay code, but I'm talking about the parts of an engine that typically use systems programming languages. Even then, you can shoehorn C# into that role with some tweaking and AoT compilation (which is a testament to the C# ecosystem's versatility). But I was just explaining why I think the word "slow" was used regarding the C# language in general, even though it's not perfectly technically correct.
- orthoxerox 5y agoThere's also Terraria, which is the 15th best-selling game of all time. Written in C# (XNA).
- sli 5y agoMentioned elsewhere in the thread, the author might be alluding to the quickly-aging Mono implementation as that's common in game engines with C# support (e.g. Unity and Godot).
- deleted 5y ago[deleted]
- NWoodsman 5y agoWhat happens when a best seller loses its language support? Isn't XNA deprecated?
- orthoxerox 5y agoThere's always FNA.
- bartwe 5y agoMy last 8 yrs of game development have been in a good part about how to make c# go fast, and it is definitely possible, but you will have to write in a style that is different from the norm.
- pjmlp 5y agoBefore C and C++ became widely acceptable for game development, we used to read these bibles like these, https://www.jagregory.com/abrash-black-book https://www.jagregory.com/abrash-black-book https://www.amazon.com/PC-Intern-Encyclopedia-Programming-Developers/dp/1557553041 https://www.amazon.com/PC-Intern-Encyclopedia-Programming-De... https://www.amazon.com/Black-Art-Game-Programming-High-Speed/dp/1571690042 https://www.amazon.com/Black-Art-Game-Programming-High-Speed... Very little regular C and C++ code, plenty of inline Assembly.
- Rochus 5y agoCan you please elaborate on that, or provide some links?
- bartwe 5y agoA few other commenters hit the points better, but mostly it comes down to avoiding allocating objects every frame/tick. In part this is through avoiding LINQ, lambdas, yield return, async etc. (fine to use in code that is run once like startup, or on relatively rare triggers) Using struct, arrays of struct/value, Span<>, ref, fixed etc. to keep memory access sequential or on stack. Use mutable structs, avoiding properties, avoiding struct constructors, moving throws into utility methods, etc. to support (the rather weak) optimizer to do more inlining. And move data processing of arrays of struct with tight loops, like compression, lighting, meshing, pathfinding into a native c++ dll/so or if applicable gpu. (c++ autovec/simd optimizations or much better than what the clr optimizer currently provides)
- Rochus 5y agoOk, I see, thanks. Why then using C#/.NET at all if you have to do without many (most?) of the conveniences of this technology, and even have to consider to implement parts in C++ for performance reason? Why not directly e.g. C++?