9 ms·
.NET GC Internals mini-series
- kyberias 6y agoHow do I know this person really knows about .NET GC internals for me to spend any time watching some videos?
- PieUser 6y agoFaith.
- ojnabieoot 6y agoYou could make a similar argument about... any video, song, essay, etc, created by anyone. So I’m not sure what the point of your comment is. I think you are getting at the fact that there’s a lot of bad-faith grifters out there who prey on entry-level devs. This is a legitimate concern! But in my experience it’s pretty easy to sniff those folks out with a superficial investigation. You don’t want to “spend any time” watching the video but I think you can spend two minutes skimming their other work, their CV, etc. I myself didn’t know anything about this person so I poked through their blog a bit. They are clearly marketing their education business (and I am not their target audience) but also seem to know what they’re talking about. More to the point: their material appears to be sincerely helpful to intermediate (and even advanced) NET devs. This relatively short post on unsafe array access in C#[1] although not especially deep, does at least dive into the runtime / IL internals enough to give a clear picture of what the unsafe code is actually doing. I haven’t watched the video either but they are creating good-faith tutorials, they are obviously capable of understanding the .NET GC, and there’s no reason to suspect they would change type and BS their way through a new video series. [1] https://tooslowexception.com/getting-rid-of-array-bound-checks-ref-returns-and-net-5/ https://tooslowexception.com/getting-rid-of-array-bound-chec...
- Avalaxy 6y agoThe author is MVP in .NET and author of the book Pro .NET Memory Management.
- jitbit 6y agoYep, and this info is 2 clicks away, literally. Select his name, right-click, "search in Google".
- WalterGR 6y agoOr hamburger menu -> About.
- buybackoff 6y agoAnd that book is as big as War and Peace by Tolstoy and Atlas Shrugged by Rand. So if you want to know the role of an individual memory allocation in the history of the entire application performance, it's a goto thing.
- jpfed 6y agoNot that this proves anything, but this author's twitter account is followed by: * David Fowler (ASP.NET Core creator) * Andy Gocke (Lead developer for the CLR) * Jared Parsons (Lead developer for C# Compiler team) * Miguel de Icaza Presumably if he wasn't saying anything worth listening to, they would have unfollowed him by now.
- bargl 6y agoWhile actually a good question, I am reading a bit of snark here. Don't spend your time on anything you don't want to, but if you want to learn about .NET GC then either research the author or research other deep dives into .NET GC. To research the author you could. Go to the About page on their blog... You could also look them up in Stack Overflow. https://stackoverflow.com/users/2894974/konrad-kokosa https://stackoverflow.com/users/2894974/konrad-kokosa You could watch the first 10 minutes where he addresses this.
- NicoJuicy 6y agoA minimal amount of effort would lead to an author with very good reviews ( 5/5 on amazon)
- fctorial 6y agoJust read the source code. It has everything you'll ever need: https://raw.githubusercontent.com/dotnet/runtime/master/src/coreclr/gc/gc.cpp https://raw.githubusercontent.com/dotnet/runtime/master/src/... Or spend an hour listening to this person. Who knows his videos might have some bits of important information.
- mustak_im 6y agoHe's very well known in the community. If one has been in any talks regarding .net gc, chances are they meet him there. Oh yeah he is also the author of an entire book about .net gc Pro .NET Memory Management. So I trust he knows what's he doing.
- tester756 6y agoWhy .NET still has no interface for serious, custom GCs?
- MarkSweep 6y agoCoreCLR does have the ability to compile the GC as a DLL and then choose different GCs are runtime by loading different DLLs. Search for FEATURE_STANDALONE_GC in the code base. This feature is enabled in the official builds though.
- tester756 6y agoYou meant "local GC" initiative? Ain't that relatively young, not so mature and and designed with specific GC design in mind interface?
- swgillespie 6y agoIt is. A few key assumptions are based into the runtime, namely that the GC is a generational GC with contiguous regions and that the GC doesn't need a read barrier, among many other things. There's a bunch of assembly in the runtime that embeds some implementation details of the GC in a way that's hard to decouple. The API came about by untangling the GC and the rest of the runtime; it took a lot of work and the resulting API probably isn't what we'd choose if we were building a GC with it in mind from day 1, but the whole scheme of sideloading a GC works pretty well.
- kkokosa 6y agoYou may be interested in watching my talk about it at NDC - https://www.youtube.com/watch?v=zVbTmgbiZsA&t=23s https://www.youtube.com/watch?v=zVbTmgbiZsA&t=23s
- graycat 6y agoMaybe for some readers: Likely GC abbreviates garbage collection. Going way back, some programming languages have permitted dynamic storage allocation, that is, a programmer using that language could during execution of the program ask for storage, that is, bytes in main memory, to be allocated, i.e., made available for use. Later the programming could free that storage. E.g., early versions of the programming language Fortran did not offer dynamic storage allocation, but some programmers would implement their own, say, in a Fortran array. Then for pointers to the allocated storage, just use a subscript on the array name. The array might be in storage called COMMON which to the linkage editor was external, thus permitting all parts of the program to use dynamic storage. The programming language PL/I had versions of dynamic storage AUTOMATIC, BASED, and CONTROLLED. The programming language C has storage allocation via the function MALLOC and freeing via FREE. Well, first cut, intuitively can think of garbage collection (GC) as automated dynamic storage freeing. In the case of the original post (OP) of this thread, what is going on is, in the .NET languages, C#, Visual Basic (VB), F#, etc., can, e.g., in a function, allocate storage, e.g., with the VB statement ReDim, likely use that storage, have flow control leave that function, leave the storage allocated, and, then, have garbage collection notice automatically when that storage will not be used again and free it, i.e., make it available again for allocation and use. In addition, likely the code for some programming language features need at least dynamic storage and might use GC for freeing. The broad idea of garbage collection is old, in several programming languages goes back decades. E.g., in PL/I, AUTOMATIC gave automatic storage freeing. Why should .NET implement garbage collection, that is, why bother? Otherwise sometimes programmers forget to do the garbage collection themselves resulting in allocated storage growing until it is too large. One of the old examples was from cases of handling exceptional conditions; in some cases the code that got control did not have the data to know what storage should be freed. GC has some challenges: First, in a rich language, it can be not easy to know what storage should be freed. So, there can be some bugs in GC implementations. Second, GC takes time, and maybe in some situations, that is, in some programs, takes too much time and results in, say, noticeably slower response time. One place where GC tends to be unwelcome is real time programming where want the software to respond in no more than a few milliseconds to external events that occur at unpredictable times. One of the main ideas for GC implementation is reference counting where the programming language compiler inserts extra code that, for each instance of appropriate cases of allocated storage, keeps track, say, just a count, of essentially how many variables in the code (for each thread of execution) might use, reference, the storage. Then for such an instance of storage when its reference count reaches zero, free the storage.
- Google234 6y agoIs this the GC that’s contained in one single 50,000 loc file?
- npalli 6y agoYes, a 43K line file. https://raw.githubusercontent.com/dotnet/runtime/master/src/coreclr/gc/gc.cpp https://raw.githubusercontent.com/dotnet/runtime/master/src/...
- the_duke 6y agoIs this somehow concatenated together in a build process, or is it actually written and maintained like that?
- UK-Al05 6y agoOriginally it was written in lisp then translated using a tool. But I believe it's maintained like that.
- tester756 6y agoI think this lisp part was in this talk, but I'm not 100% sure what he did say
- kkokosa 6y ago"I'm not 100% sure what he did say" - this makes me a little worries. What wasn't clear exactly? I've hoped that the GC history from 48:50 covered "the Lisp part" good enough.
- tester756 6y agoI've been jumping through video to see what is this about and heard something about lisp2cpp transpilation myth (that I've heard before) It's not related to your english, ability to express or something. Anyway, thanks for the effort
- u678u 6y agoAnyone have a good comparison of .net vs java GCs? I never had trouble with the former but Java has been terrible. I'm not sure if its just my project or having the xmx memory cap.
- The_rationalist 6y agoZGC is the state of the art
- na85 6y agoI don't use Java but I was under the impression that it has the most sophisticated gc's available. Isn't the Shenandoah GC supposed to be able to gc asynchronously without pauses?
- majkinetor 6y agoI am quite interested in this also and I confirm it from empirical standpoint - I never had a single episode of .NET GC but it was usual stuff on Java apps. We even had 3 month session in GC optimization directly with the guy working at Sun on it.
- pjmlp 6y agoRegarding Java GC's it depends pretty much which JVM implementation, and what GC is chosen from the pleothara that each vendor packages. Even if it has the same name to other vendor, it doesn't mean it is 1:1, as each vendor fine tunes their own implementation. This also applies to .NET actually, as there are other implementations besides .NET Framework/Core. So it always boils down to profiling.
- throwaway189262 6y ago.NET GC is nothing to write home about, pretty standard with long stop the world phase. It's not super interesting so nobody raves about it. Java's new collectors ZGC and Shenandoah are state of the art, perhaps the best GC's in the world. There's collectors with lower latency and higher throughput but nothing out there that achieves both like Java's new collectors do. It's a large part of why you hear that Java "performs better in production" than Go and C# even though those languages are faster in micro benchmarks. Java doesn't have value types and generates a ton of garbage but the collectors are good enough that it's still competitive with these faster languages. Some will tell you that Go's GC is state of the art but I disagree. Last time it came up I started a huge flamewar in the comments so I'll avoid comparing them :).
- mars4rp 6y agoPlease forgive me ignorance, but why can't I manually delete an object? Lots of times I know this one object is pretty big and want to delete it when I am done with it, but have to force the GC to run to clean it up.
- kevingadd 6y agoWhat will deleting it achieve if the GC doesn't run?
- Skinney 6y agoWith a GC like the one used in .NET, «deleting» an object is a noop. It wouldn’t give you any benefits over not deleting it. You only pay a price for living things (as in, some object holding a reference to it), the rest is free.
- Skinney 6y agoI guess I could provide a bit more info. A generational GC as the one in .NET allocates memory up-front, then passes out references/pointers from that allready allocated memory. When the GC is getting close to the end of the pre-allocated memory, it will analyse all living objects (the objects it can reach from the stack and global variables, and objects referenced by those objects) and copies them over to a different area of memory (generation). The area the memory was copied from, is now all garbage, and can be overwritten by new objects. I guess you could say that instead of collecting garbage, it de-fragments your living objects. If the GC still doesn’t have enough memory, it will try to allocate more. In any case. The cost of a generational garbage collector is associated with living objects, not dead ones, so manually deleting doesn’t make sense.
- KMag 6y ago> The cost of a generational garbage collector is associated with living objects, not dead ones, so manually deleting doesn’t make sense. This is true in the context of the discussion, and in general for copying garbage collectors, but it's not always true. Copying is the most common way (and the current .NET way) to implement at least the Eden generation of generational collection, but it could be implemented in other ways.
- zbendefy 6y agoTrash talk
- kkokosa 6y agoThank you for all the comments, here's the link to the second episode if you are interested: https://www.youtube.com/watch?v=OXvT9f5PPbs https://www.youtube.com/watch?v=OXvT9f5PPbs