171 points · by fogus · 15y ago · 79 comments
When will this reasoning finally die?
The LuaJIT 2.0 interpreter, written in x86-64 assembly language, is 2-5x the speed of the plain Lua interpreter, written in C. Note that this is with the JIT disabled -- it is an apples-to-apples comparison of interpreter-vs-interpreter: http://luajit.org/performance_x86.html
I recently wrote a protobuf-decoding assembly code generator that is 2-3x the speed of C++ generated code: http://blog.reverberate.org/2011/04/25/upb-status-and-prelim...
What is your evidence in support of the idea that assembly cannot be faster?
I made no such claim.
My gripe was using it as a feature, claiming that since it's in assembly, it's certainly faster, which is just simply not true. In most cases, it's the algorithm that determines performance as opposed to the details of its implementation. Assembly certainly has its place, but arguing a kernel completely implemented in assembly is faster simply due to the abstraction level they're working on does not carry much weight. Of course you'll be able to find hand-tuned algorithms that are much faster in assembly than a higher-level language, but that does not follow that "Complex software written in X is generally slower than complex software written in assembly"
Also, Lua is a poor example. It's performance was much more heavily influenced by portability and embedability.
But if you take one algorithm and implement it in both languages, assembly implementation will always be faster, thus the basis for their claim.
No one has performed controlled studies on these things - maybe they had some crummy bottlenecks, used some language feature that their compiler couldn't optimize away, maybe the benchmarks they use to determine performance are trivial (which is very often the case), etc.
Not to mention that most of an operating system's time, post boot is spent doing... what? Having the scheduler swap processes in and out? If you're running a single program that fits inside ram... it's totally fucking pointless, there's nothing left to optimize.
I have a better question. These guys are clearly smart. What the hell are they still doing in Atwood, Ontario?
Some of the important problems are NP-complete (like register allocation). Another problem is that compilers aren't that good at telling fast-paths from slow-paths (and keeping everything in registers for the fast paths). For more info see this message from the author of LuaJIT: http://article.gmane.org/gmane.comp.lang.lua.general/75426
I don't think that is the key, they key is the cost of that speed improvement. Say you spend a week to write the protobuf decoder in assembly so now it can decode in 30usec instead of 60usec. So you have an impressive 2x speed gain.
But then say, you are writing the data do a disk. Well maybe it doesn't really matter how fast you are decoding the protobuf if next you are sitting there for ages waiting for that data to be written out. That 30usec gain is nothing on top of that 10msec wait time that is coming next, so was that week a good investment f you just did for pure speed improvement? (well you might have done as a learning exercise, then speed doesn't really matter).
> But then say, you are writing the data do a disk. Well maybe it doesn't really matter how fast you are decoding the protobuf if next you are sitting there for ages waiting for that data to be written out. That 30usec gain is nothing on top of that 10msec wait time that is coming next, so was that week a good investment f you just did for pure speed improvement? (well you might have done as a learning exercise, then speed doesn't really matter).
haberman's parser (1460 MB/s) outperforms Google's C++ parser (260 MB/s) more the 5x. Note that even in the disk example, a fast SSD will have enough bandwidth to throttle the CPU on Google's parser. On top of that, this is FOSS, which means his weeks of investment is multiplied every time someone downloads and uses his code.
And in any case, it's still not an argument for writing an entire OS in assembly, but rather only a few important segments of the code.
Wouldn't we expect it be executing the JIT-compiled code (i.e., doing useful work) most of the time?
If so, doesn't that really make the opposite point, that compiler (JIT or no) generated code is plenty fast?
Until then, compilers will be mindbogglingly retarded piles of crap that produce code 10, 20, or more percent slower than a human. Doubly so on anything other than x86. Add a factor of 10 if SIMD is involved.
Part of the problem is simply that compilers typically cannot know the same information the programmer knows: assumptions about alignment and aliasing, for example, that the programmer knows, but the compiler doesn't.
But even if they did, there are plenty of cases where "producing good assembly code for a given algorithm" is infeasible with a brute-force approach, requiring the imprecise-but-effective pattern-matching of a human brain -- or something similarly powerful.
So while yes, there are probably a small number of cases where it's still worthwhile to write stuff in assembly, it's not worthwhile to talk about it as though it's a good thing (I would guess you should only do it when it becomes a necessity, and complain about it a lot, rather than presenting it as a feature)
Compilers are good, but they must ensure correctness for any source code. On the other hand, you now exactly what you need thus you can drastically simplify / optimize the assembly code.
What they do emphasize is that the operating system was written in assembly, and while I don't know the members of the team personally, I'd guess anyone who has completed a project such as this (with this level of polish and utility) is at least potentially capable of being smarter than your average compiler.
I'd also like to state that I do agree, for a vast amount of software development, the convenience of higher-level languages and API's outweigh the associated performance disadvantages but for some programs, the ones that talk directly to hardware and who's library functions are called billions of times a second by application programs (and let's add, that are written far less frequently than application-level code) the assembly approach is justified.
Of course you're welcome to build something similar in a compiled language and prove us all wrong :)
Programming assembly is actually fun (for some of us) and gives you a level of intimacy and insight into the machine that no other language can provide.
OK maybe FORTHThat's kind of funny if you think about it. Are people really writing OS's in VB these days?
See a great discussion at http://electronics.stackexchange.com/questions/14527/any-pro...
(The Java demo you saw was probably Jazelle, which is a processor module on ARM chips that runs (some) Java assembly language instructions natively, instead of using a virtualized processor. That's possible for a lot of VM-based languages, but it's not running Java.
"hardly anyone used" <-- this is why assembly still survives. I still use a fair bit of it for commands that glibc doesnt wrap (i.e. RDTSC)
It's not my impression that modern OSs has a habit of getting in the way of pure computation - and when the computation is done, I'd much prefer a solid filesystem/network stack to get the results out of the door.
But as an academic/tinkering/hacking project, it's awesome. If assembly was in my backlog of stuff I want to learn/play with, this would be an obvious thing to get started on.
In contrast, IBM's Blue Gene series runs Compute Node Kernel which is not Linux and uses offset-mapped memory. This obviates the need for a TLB. The rest of the OS is also stripped down compared to Cray's already lean CNL. Performance variability on Blue Gene is usually reliably less than 1%.
I think BareMetal looks rather silly and will probably not be used for anything serious, but ordinary Linux or BSD is a dubious choice for HPC.
Considering it is such a "from scratch" kind of project and given the progress so far, it seems to me like it might be more of a "let's see if we can" curiosity type thing rather than a project that an end user might actually want to use for anything practical.
But if you a large HPC cluster, getting 13% more of each compute node definitely worth the trouble.
EDITED: see link in child's post
They should mandate a very small (but popular) set of hardware that will be supported so if you want to use it that's it and then it reduces their support issues (they could even sell pre-installed boxes). Possibly create some drivers for Virtualbox drivers to allow people to dabble with it prior to building their own compatible hardware.
I'd like to see them include much needed secondary features in Intel optimized C with a roadmap for them to be reimplemented in ASM as time permits.
If they could develop/get a static web server with the speed of Nginx (or better) I'm sure this thing would explode in popularity; I'm sure CDN's etc. would see the benefits.
How much gains are you making by optimizing the OS?
Personally I would have preferred a custom filesystem designed for the application but I can see the convenience of being FAT-compatible. I wouldn't expect these nodes to keep much data locally (if any).
FPGAs can be programmed to give the answer in the time it takes the gates to propagate which is usually damn quick. None of these "cycles" things that CPUs use up.
The requirements for an operating system have changed drastically with this new way of thinking about what it means to run an operating system. The requirements can be as low as supporting a single process that can talk tcp and (maybe) to disk. Look at Haskell Network Stack, it provides network support to an application and you don't need an OS proper, just Xen.
I'm very excited to see where highly lightweight OSes end up.