5 ms·
.NET 4.5 includes new garbage collector enhancements for client and server apps
- kevingadd 14y agoBeing able to disable blocking gen 2 GCs for a period of time will be really useful for games and multimedia applications. You can disable the blocking GC during your update/render logic, then turn it back on while your main thread is blocked on vertical sync! Being able to do this kind of scheduling aware GC would be a big boon for browser environments too. I've been pushing browser developers to do this and hopefully having working examples of it in other environments will help motivate them - see https://bugzilla.mozilla.org/show_bug.cgi?id=730113 https://bugzilla.mozilla.org/show_bug.cgi?id=730113 for one example of how this might be done.
- tinco 14y agoThat is not a very good idea, a gc could easily take more time than your vsync, even if you didn't leak anything. It's smarter to profile your game and make sure it doesn't leak any memory, and perhaps use this feature to disable the GC altogether until play is interrupted.
- kevingadd 14y agoHow exactly do you propose 'not leaking memory' in runtime environments where everything creates garbage? In .NET you at least have structs, but other environments (like JS as I gave as an example) make it impossible or near-impossible to be garbage-free. Controlling the timing of your GCs is a win there, even if a long GC can make you miss a frame. Half a GC happening during vsync instead of none of it is still a win because the hitch will be smaller.
- tinco 14y agoWether the language has structs or not has nothing to do with leaking garbage. I think it's even possible to not leak memory in js, though I haven't tried that. It is absolutely not true that everything in .net creates garbage. If you leak memory in your render/update loops then that's a problem. You prevent it by never calling new and never using syntax that implicitly allocates (like foreach). Anyways, the half GCs still happen even if you enable the no gc mode. Going for the small hitch instead of for no hitch at all seems to be setting the bar too low for me. (no matter how small the hitch, if it consistently happens players will notice it and your game experience will be seriously degraded) edit: just checked out your profile, you obviously know more of what creates garbage in js than I do, so I'll believe you if you say everything creates garbage :)
- mbq 14y agoYou may end up writing C...
- tinco 14y agoIf you regard watching your memory allocations as a C thing, then perhaps. When you build real time video games this is just how it goes, whatever language you work in. You need to make sure everything is allocated _before_ you enter the game loop, wether it's C or C#. Even when you feel bothering with those details is like programming C, you still have classes, namespaces, a sane compiling and linking system and a terrific standard library. Which in my opinion makes it infinitely more comfortable than coding in C.
- mbq 14y agoNote that the usually the OOP system heavily promotes short-lived memory allocations and the standard library is build around it.
- kevingadd 14y agoForeach in C# doesn't always create garbage, FYI. Enumerators can be structs - List<T>'s is, for example. It's certainly possible to write an application that doesn't structurally create garbage, but doing so isn't a universal win. Garbage-free coding patterns are more verbose, harder to get right, and often slower than relying on the GC. The reason a small hitch is better than no hitch is that if your game is running faster than your target framerate, hitches can be small enough to actually hide between frames - and control over when the GC occurs can allow you to reliably hide your GCs there.
- alexro 14y agoSustainedLowLatency is a killer for many types of scenarios. One is when you create many objects that you don't intent to GC throughout the life of the app, dictionaries for example. Memory is cheap, being able to use it to increase performance of a managed app makes me really excited with how c# can be used in apps typically written in C++
- thebluesky 14y ago> "The new background server GC in the .NET Framework 4.5 offloads much of the GC work associated with a full blocking collection to dedicated background GC threads that can run concurrently with user code, resulting in much shorter (less noticeable) pauses. One customer reported a 70% decrease in GC pause times. " Concurrent garbage collection. Not that impressive in 2012. Java has had concurrent GC for at least a decade: JDK 1.2.2 Java had a switch for that in the late 90's already: -Xconcgc Use concurrent garbage collector (1.2.2_07+) JDK 1.4.2 http://java.sun.com/docs/hotspot/gc1.4.2/#4.3.%20When%20to%20Use%20the%20Concurrent%20Low%20Pause%20Collector|outline http://java.sun.com/docs/hotspot/gc1.4.2/#4.3.%20When%20to%2... also: http://research.sun.com/techrep/2000/abstract-88.html http://research.sun.com/techrep/2000/abstract-88.html The world has moved on: http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html http://www.oracle.com/technetwork/java/javase/tech/g1-intro-... http://researcher.watson.ibm.com/researcher/view_project_subpage.php?id=175 http://researcher.watson.ibm.com/researcher/view_project_sub...
- kevingadd 14y agoThe world has moved on from using threads? Citation, please. ;)
- thebluesky 14y agoThe world has moved on to more advanced concurrent GC implementations. Citations above.
- thebluesky 14y agoAnother citation from 4 years ago for good measure: http://www.oracle.com/us/technologies/java/oracle-jrockit-real-time-1517310.pdf http://www.oracle.com/us/technologies/java/oracle-jrockit-re...
- tinco 14y agoMany other languages still don't have it, as I understand it implementing a concurrent garbage collector is always impressive, whether you did it 20 years ago or now. I think this is indicative of their priorities. Java has had to fight the general opinion that it is a slow platform, so they built the best garbage collecting vm you could imagine. .Net has had to fight the opinion that it is just Java but on windows, so they built a multiple language oriented vm that enables language features so varied that even the standard java-like language C# rivals ruby and python in expression.
- deleted 14y ago[deleted]