4 ms·
Anyone know why they are building in C as opposed to a newer language like Rust or Go? I mean, if you're going to start from scratch, might as well go all the w
by javajosh 9y ago
Anyone know why they are building in C as opposed to a newer language like Rust or Go? I mean, if you're going to start from scratch, might as well go all the way, right?
- sunstone 9y agoThey have an AI now that guarantees no subtle flaws in the C code.
- bitcoinmoney 9y agoC is still the king in performance I believe. Linux still has assembly code apart from C for those crucial performant sections. Remember if you are talking at the HW-level you don't have the luxury of libraries and I doubt Go/Rust would be of any help unless you build the ecosystem for it. Something like the implementation of coreutil binaries can benefit from Go/Rust but not the OS-code itself.
- steveklabnik 9y agoIf Rust is significantly slower than C, it's a bug.
- fooker 9y agoYeah, just one that will take a decade of compiler optimizations to solve. C and C++ didn't become what they are today overnight.
- steveklabnik 9y agoWe share an optimizer with clang thanks to LLVM; we get to take advantages of those decades already.
- fooker 9y agoClang and LLVM have evolved together for a while. It is pretty difficult to get similar results with other LLVM frontends. You don't have to believe me, just write a reasonably complicated algorithm (say.. a naive SAT solver) with both C++ and Rust (or Swift or $NEW_LANG) and compare the speeds.
- steveklabnik 9y agoYou don't have to believe me either; if you try it, you should generally see that they have the same performance.
- javajosh 9y agoWhen you say "naive SAT solver" do you mean one where you hard-code a boolean formula with N variables and then check every possible solution (from 0 to 2^N)? If so, does this kind of program accurately characterize the kind of work a kernel does?
- fooker 9y agoNo, something like the CDCL algorithm without domain specific heuristics and tweaks. I expect that is fairly representative in terms of ..say.. common data structures needed in most systems.
- fooker 9y agoHere are some fairly realistic examples. 1. Rust : http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=rust&lang2=gcc http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... 2. Swift : http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=swift&lang2=gcc http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan... As for a SAT solver, I was not speaking out of my ass. Here is one try that got a fair bit of attention. https://github.com/mishun/minisat-rust https://github.com/mishun/minisat-rust
- steveklabnik 9y ago
- simula67 9y agoI think Go has mandatory garbage collection. I think you can turn it off, but you can't manually manage memory. Manually managing memory is important when you are writing real-time software like operating systems. You don't want the garbage collector to kick in without being asked when you trying to complete a task within a deadline
- lukevers 9y agoYou could manually manage memory in Go if you want. Here's a few links: https://news.ycombinator.com/item?id=9545873 https://news.ycombinator.com/item?id=9545873 https://github.com/teh-cmc/mmm https://github.com/teh-cmc/mmm
- d2kx 9y agoThey are actually using lots of Rust within Fuchsia/Magenta now and have been for months.
- javajosh 9y agoI poked around and didn't see any Rust code, and the github stats say C 49.0% C++ 45.4% Makefile 2.9% Assembly 1.1% Shell 0.8% Objective-C 0.4% https://github.com/fuchsia-mirror/magenta https://github.com/fuchsia-mirror/magenta
- swiley 9y agooh jeez, a kernel in C++... The only thing I dislike about Linux is that it drags gcc with it, for this you need g++ too.
- kamouth 9y agoI don't know anything about kernel dev: why would C++ be a bad choice?
- bmon 9y agoI'm not an expert, but I think it's because c++ is _heavy_. Start using a few features like genetics and suddenly your binary and compile times grow substantially. You only need to look at chrome to see this happening.
- krylon 9y agoMicrosoft and Apple develop their respective kernels in C++, and AFAIK, developers are limited to a very restrictive subset of C++, classes are forbidden, so are exceptions, so are new/delete. I think, templates are forbidden, too, but I am not certain. Once you shrink C++ down to such a subset, it is substantially less heavy. I do not think I am qualified whether that makes it a better choice, but means there are examples of fairly successful operating systems whose kernels are written in C++.
- CardenB 9y agoProbably because Google's C++ tooling is top notch and their developers are all proficient already.