5 ms·
> People expect the page to scroll at 60 FPS and that rules out GC pauses longer than 16 ms How do people writing games in Java or C# deal with this? Gaming is
by tzs 13y ago
> People expect the page to scroll at 60 FPS and that rules out GC pauses longer than 16 ms
How do people writing games in Java or C# deal with this? Gaming is an area where people expect smooth, high speed performance.
- munificent 13y agoObject pools: they allocate objects upfront and re-use instances instead of creating and releasing them.
- Arelius 13y agoThis is one trick, among many. Most of which negate many of the advantages of GC in the first place.
- zurn 13y agoThe advantages of memory-safety remain.
- pcwalton 13y agoSome advantages of memory safety remain. When using pools, you don't get protection against use-after-free or leaks. It does somewhat mitigate the consequences of those, however: it's much harder for a use-after-free to become a security exploit in a pool in a GC'd language, for example.
- zurn 13y agoSounds like you have a specific kind of object pool implementation in mind? Invalid object refs don't have to break the memory safety, cf. weakrefs. An object pool can also be implemented without unsafe bulding blocks or other language support, as a pool of objects that are manually recycled after the pool lifetime is up. Then a bug could let you confuse a previous generation object witha current-gen one, but would not break memory-safety either.
- chr1 13y agoJava or C# are not used in the kind of games that pushes hardware to the limits, really complex games are still in c++.
- venomsnake 13y agoLast time I was interested for big games it was - C++ engine and above it Lua or C# scripting for majority of AAA titles.
- Arelius 13y agoYou'll notice that most games are not written in Java or C#. It's much more common in small games that have a lot more cycles to spare. And even still, it often becomes a problem. Generally it's solved by being very careful with object allocation as to not require GC during gameplay. Or some other trick to force GC to take less time than budgeted. Also keep in mind, a lot of games are designed to run much closer to 30 FPS these days. Which gives you a lot more time to deal with GC.
- deleted 13y ago[deleted]
- eropple 13y ago> How do people writing games in Java or C# deal with this? Gaming is an area where people expect smooth, high speed performance. Short, mean answer: poorly. Longer answer: they sacrifice the benefits of managed languages. They forego immutability and controllable object lifetimes for the use of object pooling to prevent the garbage collector from going nuts. And many still target 30fps in order to minimize the effects of variable latency. I used to do this; I'm porting my stuff from XNA/MonoGame to my own OpenGL/GLFW/OpenAL engine in C++ because I grew unsatisfied with the performance and limitations inherent in the process. Many of the biggest benefits of managed languages are blunted with games in other ways, too. The CLR, for example, should be a huge boon for scripting--the DLR is a fantastic concept, for example. But dynamic code requires codegen, and System.Dynamic doesn't work in Xamarin's iOS product. So if you want to bring a game with scripting from Windows/OS X to iOS, you're boned. (Java has the same problems; Groovy, while a great scripting language, doesn't run on Dalvik or on IKVM-over-MonoTouch. Rhino's LiveConnect doesn't work there either.) On the other hand, I use AngelScript and expose C++ objects and methods to it, computed statically at runtime but executable via interpreted scripts, for the best of both worlds without breaking my back to do it. Memory management just isn't that hard and the performance and compatibility of native code just can't be touched right now.
- rossjudson 13y agoObject pools were good JVM thinking 10 years ago. It's been a very long time since they made any sense for memory-based objects. Unity manages to do quite a bit with the CLR on a cross-platform basis, and that looks like Javascript to me. Horrors! AngelScript has Garbage Collection! But since it didn't come from the JVM, I guess it's OK. http://www.angelcode.com/angelscript/sdk/docs/manual/doc_memory.html http://www.angelcode.com/angelscript/sdk/docs/manual/doc_mem... > Memory management just isn't that hard Every victim of a use-after-free just cried out in anguish. Your world weeps at 60 fps. Keep in mind the original question: What's a good language for implementing a browser? The number one requirement for a browser today is not performance. It is security. A decade of effort has been put into the major browsing engines to snatch pseudo-victory from the clutches of determined hackers. A great deal of that effort has been necessary because of the desire for "speed", and the fallibility of those who believe memory management "just isn't that hard".