News for hackers. Stuff that matters.
Re:It’s Faster Because It’s C by JoeAltmaier on Tuesday July 13, 2010 @09:55AM (#1511349)
Java leads the programmer into using bloated libraries, which absolutely litter the Java landscape. Its very hard to measure or even predict what effect a Java interface will have on your solution.

I agree with the author, the language has no intrinsic slowness, its the tendency to use a triply-nested abstraction for every trivial purpose (a hash table of objects containing references to a database API...) instead of Hey! a pointer, that lead the app programmer down the primrose path.

Re:It’s Faster Because It’s C by _delirium on Tuesday July 13, 2010 @11:41AM (#1511672)
Compared to C that's true, but bloated libraries aren't exactly absent in the C++ world (one of many reasons that "C/C++" is usually a weird generalization). Nested templates of templates are all over the place, and as for pointers, it's common to wrap those too using one of the various smart-pointer classes.

C often leads to bad algorithms, though, for the same reason it often leads to lean code tuned to the specific application at hand. Absent many general library functions, the C world is littered with lots of custom reimplementations of data structures and algorithms, not all of which are the best (and a lot of which are actually buggy). Even when they're good, they tend to have short shelf-lives: much hand-optimized 90s-era C code is now slower than more naive implementations, because the optimizations used to save some instructions often actively harm cache performance.

Re:It’s Faster Because It’s C by JoeAltmaier on Tuesday July 13, 2010 @03:24PM (#1512440)
Good analysis. I would amend: templates usually improve code efficiency, because the compiler can see through abstractions and generate (larger but) much faster code.
Re:It’s Faster Because It’s C by _delirium on Tuesday July 13, 2010 @10:13PM (#1513367)
I think that's often true (one common example is stl sort versus C stdlib's qsort(), which is often a big win because of inlining a datatype-specific comparison operator), but I think there are quite a few cases where the object code bloat you get from multiplying the code by the number of types it's instantiated for (vs. using a polymorphic/generic function) kills your cache more than enough make up for any optimization win.
Re:It’s Faster Because It’s C by JoeAltmaier on Wednesday July 14, 2010 @09:43AM (#1514514)
Sure; but it certainly depends upon the frequency of use of each instance etc. But in general, shorter code is a good choice of optimization
Re:It’s Faster Because It’s C by mfukar on Tuesday July 13, 2010 @12:01PM (#1511740)
"much hand-optimized 90s-era C code is now slower than more naive implementations, because the optimizations used to save some instructions often actively harm cache performance."

On the same hardware? That seems unlikely - do you have a specific example in mind?

Re:It’s Faster Because It’s C by a-priori on Tuesday July 13, 2010 @12:40PM (#1511908)
He means that the hardware has changed. Micro-optimization these days mostly has to do with optimizing cache and memory I/O performance rather than reducing clock cycles as it was in the 90s.
Re:It’s Faster Because It’s C by btilly on Tuesday July 13, 2010 @12:57PM (#1511978)
Yes. On the same hardware. And I'm sure that a specific example was thought of.

To give one of several likely causes, CPU pipelines have grown much longer. As a result it is more important to avoid stalls these days. Naive code compiled with a modern compiler knows about the importance of this. For instance the compiler will know it can avoid a stall in certain cases by making sure that a read from memory that happens soon after a write obeys something called store to load forwarding restrictions. Doing that can mean extra code which would be slower on an old computer, but it is faster than a modern one.

Re:It’s Faster Because It’s C by mfukar on Tuesday July 13, 2010 @01:19PM (#1512053)
Well, if we're talking about different hardware, this whole discussion is moot - CPU (not C-entral anymore..) architecture changes render "old" optimization techniques only situational today.

At any rate, the same is true for all languages, and _delirium's point is spot on: it's not the language that matters, it's the fact that bad (or slow, or inefficient, call it what you will) code is encountered regardless. It's time we stopped language wars, don't you think?

Re:It’s Faster Because It’s C by btilly on Tuesday July 13, 2010 @04:53PM (#1512706)
The discussion is only moot to the extent that the complaint is inaccurate. It is true that code, once optimized, is frequently hard to unoptimize. It is further true that what you optimize for at one point does not match what you optimize for at another. It is also true that there is a lot of C that is now optimized for the wrong thing. And finally it is true that people who write C because they are trying to squeeze performance are more generally prone to create more of it.

As long as those facts remain true, it is fair to complain about this tendency in C code in the wild. Even though the problem clearly lies with some of the programmers the language attracts rather than with the language.

Re:It’s Faster Because It’s C by mfukar on Saturday July 17, 2010 @01:13PM (#1524179)
And finally it is true that people who write C because they are trying to squeeze performance are more generally prone to create more of it.

You can't imply "fact" and use "generally" in the same sentence, sorry.

Re:It’s Faster Because It’s C by JoeAltmaier on Tuesday July 13, 2010 @03:24PM (#1512443)
Agreed. Its like my yellow framing hammer; useful for one job, but I have other hammers. (said this before)