12 ms·
The original .NET garbage collector was written in Common Lisp
- markus_zhang 7y agoAlways amazed by the skills of people who can write language translators without much difficulty.
- pjmlp 7y agoIt only looks hard until the very first compiler design class, then it is a kind of mechanical exercise. What requires expert level are the error messages, the quality of generated code and runtimes performance.
- ohyes 7y agoyes, excepting that many have trouble with the compilers class. if you get through it and do well you're probably fine.
- klipt 7y agoCompiling from lisp is even easier because parsing is trivial.
- pjmlp 7y agoUntil the year before the one I took compilers design, the choice of programming languages for the implementation was free, except for any Lisp or Prolog derived languages weren't allowed. The responsible professor considered the final project would be too easy for anyone using them, and he was kind of right.
- zerr 7y agoOne would say Compilers is a multidisciplinary subject and I think it is fine that some parts (e.g. parsing) might be boring for some, and some other parts (e.g. optimizations, codegen) might be exciting :)
- th0ma5 7y agoI've heard a fair amount over the years of Lisp as a great code generating language. I wonder what sort of thinking took place in this intersection between writing in a macro language and imagining what the generated language would do, and then the assembler...
- markus_zhang 7y agoCan you elaborate on the part "Lisp as a great code generating language"? Just curious. I tried to learn Scheme for SICP but then switched to the Python version.
- superdisk 7y agoLisp's big strength is that since the program itself is represented in the same form as the data structures, you can very easily generate executable programs by just slapping lists together. I'd recommend going back to the Scheme version-- I initially didn't understand the cool factor of Lisp either, until I used it for a while (and found macros).
- kccqzy 7y agoI definitely recommend you to finish the Scheme-based SICP. Plenty of stuff in the original SICP like metalinguistic abstraction is just awkward or impossible in Python.
- armitron 7y agoThere is no Python SICP. It pains me to see you waste your time with someone's inferior regurgitation/butchering of material written and presented by absolute geniuses that should be considered among the highest forms of art produced in the field.
- andreareina 7y agoIf python didn't have with blocks, I could replicate the behavior by manually writing out a try/except/finally. I cannot write something to do that for me automatically (ignoring eval/exec). Where functions allow abstraction over a sequence of instructions, code generation allow abstraction over syntax, allowing the invention of new language features.
- freeduck 7y agoInteresting how Lisp is used in production
- rjsw 7y agoYou use the tools you know best. The blog author worked for TI on their Lisp Machine and for Lucid.
- cedricd 7y agoKind of production. It was initially written in Lisp, then translated to C++ to go to production and maintained / extended from there. That's a great way to prototype -- use what you know and then rewrite (or in this case transpile?)
- jdc 7y agoHowever unlike most prototypes, this one wasn't thrown away, but rather transpired into production code.
- Kipters 7y ago> unlike most prototypes, this one wasn't thrown away I wish...
- protomyth 7y ago"It's working code so deploy it now. You can pretty it up later." Yeah, I've heard that one too many times. It amazes me how much that experience changes how a developer prototypes.
- MaxBarraclough 7y agoI'm reminded that I once read of someone using the Napkin look-and-feel for Java Swing as a way of managing customer expectations. http://napkinlaf.sourceforge.net/ http://napkinlaf.sourceforge.net/ Edit Here we are: https://headrush.typepad.com/creating_passionate_users/2006/12/dont_make_the_d.html https://headrush.typepad.com/creating_passionate_users/2006/...
- alexeiz 7y ago> was written in Common Lisp and automatically translated to C++ That's the reason the .NET GC source code is still in one single massive .cpp file. I mean, look at it [1]. Github even refuses to display it. [1] https://github.com/dotnet/runtime/blob/master/src/coreclr/src/gc/gc.cpp https://github.com/dotnet/runtime/blob/master/src/coreclr/sr...
- thu2111 7y agoWell, sort of. That may explain why it started that way. The real reason appears to be that the maintainer of it is kind of crazy and appears to not be properly managed. She's actually rejected community pull requests to break it up in the past on the grounds that she just prefers it in one giant file, and doesn't believe it makes any difference to comprehension or codebase usability. https://github.com/dotnet/runtime/issues/4024#issuecomment-77922359 https://github.com/dotnet/runtime/issues/4024#issuecomment-7... https://github.com/dotnet/runtime/issues/4024#issuecomment-227222339 https://github.com/dotnet/runtime/issues/4024#issuecomment-2... Honestly the .NET code is kind of a mess compared to the OpenJDK code. The developers really don't seem quite as sharp. It's impossible to imagine HotSpot containing a source file that's 35,000 lines long, let alone dismissing attempts to improve it with ridiculous justifications like "it'll cause merge conflicts". The lines themselves are about as high quality as you might guess from something converted from Lisp and then hacked on for a decade or so by people who prefer it all in one file - enormous amounts of #ifdefs all over the place, it starts by defining its own random number generator, a mishmash of different coding styles, dead code, lots of undocumented and untunable magic numbers ... it's really a disaster zone. Behold: https://raw.githubusercontent.com/dotnet/runtime/master/src/coreclr/src/gc/gc.cpp https://raw.githubusercontent.com/dotnet/runtime/master/src/... And compare to the HotSpot GCs: https://github.com/openjdk/jdk/tree/master/src/hotspot/share/gc https://github.com/openjdk/jdk/tree/master/src/hotspot/share... (multiple algorithms for throughput vs latency, "epsilon" is the smallest GC implementation possible that doesn't actually collect anything - it's useful for learning and cases where you know your process won't last long enough to need a collection) When the CLR was first open sourced I was very curious to see if OpenJDK might now have some stronger competition when .NET was ported to other systems and made more UNIX friendly. After reading through the code and seeing how the developers acted I concluded they'd never displace the JVM.
- musicale 7y agoOh I thought this would be about the popular CLR Calcium/Lime/Rust remover liquid.
- Ice_cream_suit 7y agoHere are some articles on memory performance issues by the current maintainer of the 35,000 line GC file: https://devblogs.microsoft.com/dotnet/work-flow-of-diagnosing-memory-performance-issues-part-0/ https://devblogs.microsoft.com/dotnet/work-flow-of-diagnosin...
- register 7y agoI would be very interested to understand how the translation to C was done. I would love to prototype like that. The CL to C translators that I know produce code that is much more complicated. This is extremely clean in comparison.
- ygra 7y agoI guess with a one-off translator you can spend more time on the patterns you know you have to translate well instead of having to handle every single possibility that could potentially come up in code. At work we can do something similar with our C#-to-everything-else compiler which handles a subset of C# 5, since for many things it's easier to just change the single line in C# than spending a day implementing a complicated feature. The other reason the code is somewhat clean (albeit long) is probably that there's been 20 years of work on it. And it probably wasn't that long in the beginning.
- register 7y agoI already knew that but defining such a subset that it is at the same expressive and flexible enough is a challenge by itself. More even so if it is used to build a GC. Now I am curios: can you provide some more details about what C# subset are you using?
- ygra 7y agoWell, it's perhaps not only the language subset, but also part of the standard library you have to provide or re-implement. I don't know Lisp too well, but I'm sure there are parts of it that are not necessarily mandatory for creating a prototype of a garbage collector. As for C#, the things we don't support are: - yield statements: codegen for that is not fun to do on your own and hand-writing an IEnumerator is annoying, but not too bad. And back when we started we couldn't get the generated code from Roslyn, maybe there's a way by now to do that. - async/await (could nowadays be converted into pretty much the same in JS at least, but Task/Promise/CompletableFuture work slightly differently anyway and there aren't that many places in the codebase that need this, so they can be patched) - dynamic (no reason to use it, thus no reason to support it). - Some generic constraints, e.g. new(): We currently emit JS, TypeScript, Java, and Python, along with a number of internally-relevant output formats like documentation – and .NET generics already don't map well to Java generics (or vice-versa), and are mostly useless for JS and Python, anyway. - goto, unless for fall-through in switch Most “normal” things like types/members/statements/expressions do work properly and the subset isn't too bad working in (it's also not a particularly small subset, of course). A lot of additional work comes in getting the necessary parts of the BCL to work on the other side of the conversion, of course, but that is a separate concern next to language features.
- qwerty456127 7y agoWhy? I.e. why not some sort of Scheme? I absolutely don't meat starting a "holy war", the question is intended purely for sake of learning more about Common Lisp, what features does it have which make it a right tool for this job in particular.
- orthoxerox 7y agoThey had people who knew Common Lisp and garbage collection. Plus Scheme has no batteries included.
- lifthrasiir 7y agoBut the target language in this case (C++) is also light in terms of batteries. It is most likely that CL was at their disposal and Scheme wasn't.
- hajile 7y ago20 years ago, Common Lisp was a mature, stable environment. Scheme was (and is) much less stable. Even if Scheme were just as mature and stable, I'd guess that Common Lisp would still be an easier choice if the output target was C++. Scheme is rather functional by nature and has a core reliance on things like proper tail calls and continuations. These require elaborate, whole-program compilation so they can be optimized away. A side effect of that kind of in-depth manipulation will necessarily be output code that is far removed from the layout of the original source (making it harder to understand what is happening or hunt down bugs). Common Lisp can do functional things, but the core of the language is much more imperative. You'll wind up writing looping constructs instead of tail calls (tail calls aren't actually part of the spec though some/most implementations support them). CLOS can probably map onto C++ classes without too much trouble as well. These lower-level constructs make it easier to reason about performance. That alone isn't everything. Common Lisp allows you to provide type hints and type specifiers to the compiler. Aside from the speedups they allow in CL, they would certainly make things easier when translating to C++. If that isn't enough of a boost, basically every major CL implementation allows you to define an inline assembly block. These things certainly could be done in Scheme (for example, typed racket), but the reader and unhygenic macros in CL certainly make it easier.
- The_rationalist 7y agoI wonder when will .NET get a SOTA low pause time collector like openjdk has with both ZGC and Shenandoah Seems even more critical as C# is widely used for games
- Kipters 7y agoMost of .NET is moving towards avoiding heap allocations altogether, the latest versions improved a lot in that sense. A great example is the new System.Text.Json API, that can serialize/deserialize JSON documents up to 1 MB with 0 heap allocations, using ArrayPool
- kqr 6y agoWhich is great for Greenfield projects with engineers that keep up to date with these latest developments. If one chooses to pour time into improving the GC instead of the language, the benefits are reaped both by existing projects and new projects by old-school developers.
- Kipters 6y agoSome of these changes are happening in the runtime itself, so many projects will get benefits just by updating to a newer version (something you would have to do anyway to get GC improvements). For example, System.Text.Json is the default in ASP.NET Core 3.x, updating to 3.0 would use it instead of Json.NET unless you explicitly opt-out. In the same way many APIs are starting to accept Span<T> in addition to IEnumerable<T>, Lists or arrays, so it's easy to opt-in into that. Other APIs are using it internally to avoid copies, so you don't need to do anything to get benefits.
- mumblemumble 7y agoI'm not sure this was terribly uncommon at the time. My work for a thesis was prototyped in Scheme and then ported to C once I was sure I had all the kinks worked out. And I know I wasn't the only one who did that. I found it to be a much more efficient way to work iteratively, because software that's written in a lisp is fundamentally more amenable to change than software that's written in a language like C. Today, not so much, because the gap has closed a lot. IDEs and improvements to the ergonomics of lower level languages have made them a lot more convenient to work in end-to end, and cheap memory and compiler improvements have made it a lot more feasible to just ship code that was written in a higher level language.
- downerending 6y agoHmm. What was collecting the Common Lisp's garbage then?