4 ms·
Whenever someone repeats the tired meme of "the compiler generates better assembly code than a human", I think of cases like this one (or the many occasions whe
by adwn 6y ago
Whenever someone repeats the tired meme of "the compiler generates better assembly code than a human", I think of cases like this one (or the many occasions where I inspected compiler-generated assembly and it was atrocious). The rule of thumb should be "the compiler generates better assembly code than a human could within the time it takes to write high-level code and press 'Build project'", but that's not as catchy.
- theamk 6y agoYour rule is much weaker to the point of being useless -- you are claiming that if it took me 1 hour to write high-level code, the compiler will generate better assembly code than what I can write in 1 hour. This is obviously true in most cases -- if it takes me an hour to write task X in high-level language, it will probably take me a day or more to write it in assembly. After spending only one hour on assembly version the program will be nowhere close to completion, and likely completely non-functional. So whatever compiler produces will be much better -- it will at least work. I can believe that at some moment hand-rolled assembly will "beat" generated code (I am pretty sure that if someone spends a month optimizing assembly listing it will beat the best Rust program written in a hour), but I am not sure what the ratio is. I am sure it is not 1:1, and I suspect the ratio gets worse as program grows and there are more parts that one needs to keep track of.
- adwn 6y ago> Your rule is much weaker to the point of being useless Yes, it's much weaker, but it's not useless. The vast majority of code in a program does not need to be as fast as it could possibly be [1], so there's no point in manually implementing everything in assembly. That doesn't mean that it never makes sense to manually implement something in assembly for performance reasons. [1] And for many programs, all the code does not need to be as fast as it could possibly be.
- theamk 6y agoRight, but I called the rules "useless" because it does not tell you any actionable info -- and this is normally expected of rules. Here is a fixed version (note I added "times 20" at the end): "the compiler generates better assembly code than a human could within the time it takes to write high-level code times 20" See -- now I can make predictions. Let's say you have a function that you want to make fast, and you want to optimize it in assembly. The function took 30 minutes to write and debug. Do you have 10 hours to spare? Try assembly. No time? Leave as-is. Much more useful this way, no?
- adwn 6y agoNow it's more accurate, but even less catchy ;-) How about: "don't blindly assume that the compiler is smarter than you"
- Dylan16807 6y agoThat sounds like a special case of "nothing is perfect" and even less actionable. Especially with how vague "blindly" is.
- kroltan 6y agoMaybe "the compiler generates better assembly code per second than a human could"?
- deleted 6y ago[deleted]
- Blikkentrekker 6y agoThere may be some specific parts of assembly generation where compilers are still outperformed by men, just as there are still specific parts of chess where men still outperform machines, but overall machines beat human programmers. The argument of allowing a human programmer to spend vastly more time is hardly fair, one could also probably write a hyper-optimizing compiler that takes far longer to compile to level the playing field, and that compiler will still triumph over men in how optimized the end result is. The only real advantage overal to human programmers here is the flexibility. A man can easily be told “spend four months on optimizing this”, a machine would have to be substantially rewritten to fully take advantage of being given extra time.
- MaxBarraclough 6y ago> the tired meme of "the compiler generates better assembly code than a human" This seems incomplete. Which human? The average software developer? That doesn't say much. Few developers have the necessary expertise. Expert assembly programmers are often able to outperform compilers.
- jlcummings 6y agoBetter wouldn’t necessarily be the right qualifier, but faster, typically more repeatable, and greatly more economical with scale/workload would certainly fit as better from different vantages. With high novelty? Probably not until machine learning and compilers are deeply entangled.
- slaymaker1907 6y agoThat very much depends on the code. Program synthesis is an active area of research and the programs found would often be very difficult for a human to figure out. Of course a sufficiently determined human can always do whatever these programs do, but I do think it is unfair to give an unlimited amount of time to human optimizers.