News for hackers. Stuff that matters.
Re:Pointers Are More Abstract Than You Might Expect in C by pests on Monday July 02, 2018 @12:31PM (#17443065)
I don't believe it is possible to hand tune every program to beat a compiler.
Re:Pointers Are More Abstract Than You Might Expect in C by MaxBarraclough on Monday July 02, 2018 @12:39PM (#17443141)
More a question of practicality, no?

Programmers are creative, compilers are well-tuned machines. Sometimes it's tough to beat a compiler's code, but I'm not sure that 'impossible' is meaningful.

Monkeys with typewriters could function as a highly parallel superoptimiser, after all.

Re:Pointers Are More Abstract Than You Might Expect in C by jeremiep on Monday July 02, 2018 @01:35PM (#17443713)
When you realize the compiler's optimizations only account for about 10% of the total program's performance you find that the other 90% is entirely up to the programmer.

Architecture, data structures, batching operations, memory locality, and a bunch of other metrics are all concepts the compiler can't really help you with whatsoever and they have a much larger impact on performance than the 10% the compiler is actually able to optimize.

The problem is that either programmers don't care, or they can't make the distinction between premature optimizations and architecture planning.

Re:Pointers Are More Abstract Than You Might Expect in C by MaxBarraclough on Monday July 02, 2018 @05:39PM (#17445544)
You're right to emphasise good data-structures and algorithms (also concurrency, parallelism, etc), but compiler optimisation is nothing to sneeze at. '10%' is laughably off-base.

From a quick google: compiler optimisation can accelerate CPU-bound code to over 5x the unoptimised performance. https://www.phoronix.com/scan.php?page=article&item=clang-gc...

Re:Pointers Are More Abstract Than You Might Expect in C by jeremiep on Tuesday July 03, 2018 @02:45PM (#17452706)
They seem to be benchmarking very specific things and not actual applications. These numbers do not hold in the real world.
Re:Pointers Are More Abstract Than You Might Expect in C by emodendroket on Monday July 02, 2018 @02:01PM (#17443967)
In a sense you're right, but hand-tuning assembly is kind of an orthogonal problem to determining whether you're using the right algorithms and data structures.
Re:Pointers Are More Abstract Than You Might Expect in C by steveklabnik on Monday July 02, 2018 @01:56PM (#17443924)
Where do you get that 90/10 split from? Just curious.
Re:Pointers Are More Abstract Than You Might Expect in C by jeremiep on Tuesday July 03, 2018 @02:42PM (#17452693)
Talks from Mike Acton and Scott Meyers, specifically "Data-Driven Development" and "CPU Caches and why you should care" respectively.

I forgot exactly where I got that number, but it's been a pretty good metric so far.

In a nutshell; the compiler is great a micro-optimizations and absolutely terrible at macro-optimizations. The former will get you a few percent of perf boosts while the later usually results in orders of magnitudes of performance gains.

Its near impossible to apply macro-optimizations at the end of a project without massive refactors.

Re:Pointers Are More Abstract Than You Might Expect in C by steveklabnik on Tuesday July 03, 2018 @06:12PM (#17453986)
Cool, I'll check those out, thank you!
Re:Pointers Are More Abstract Than You Might Expect in C by Narishma on Tuesday July 03, 2018 @06:29PM (#17454105)
I believe the 10/90 number may be from this talk, though I don't have time to rewatch it to confirm: https://www.youtube.com/watch?v=rX0ItVEVjHc
Re:Pointers Are More Abstract Than You Might Expect in C by kbenson on Tuesday July 03, 2018 @02:06PM (#17452399)
But it should be possible to hand tune to match a compiler, right? And that would mean the compiler was not faster, which is the general claim I was calling into question.
Re:Pointers Are More Abstract Than You Might Expect in C by mhh__ on Monday July 02, 2018 @04:23PM (#17445025)
How so? Compilers aren't magic, you can - by definition (Assuming the current state machine style (no AI or nuthin') of compilers ) - you can just manually compile it.

Compilers are clever, but humans can also be really clever: They know how to think - You can change the algorithm entirely.

For practical reasons however (Premature optimisation also), trust your compiler.