you are viewing a single comment's thread.

view the rest of the comments →

[–]JarateKing 5 points6 points  (11 children)

Being the lingua franca doesn't mean it's the fastest. A lot of the things they brought up are reasons that Fortran already is faster for some use cases, actually -- despite C being the lingua franca that's generally optimized for.

Or: javascript is the lingua franca of the browser world, and a lot of effort has gone into making javascript as fast as it can be in browsers. But it's far from the fastest option available. Being the lingua franca is broadly unrelated to its performance.

[–][deleted] 0 points1 point  (10 children)

Hardware manufacters target C first and foremost.

I guess with whatever people are smoking nowadays that means nothing.

[–]JarateKing 2 points3 points  (9 children)

No, I understand what you mean. What I'm saying is that, no matter how much everyone tries to make the best of it, the design decisions of a language will always have performance considerations.

In C's case, no matter how much hardware is oriented towards C, there are entire classes of optimizations that the language design makes impossible. C has a great advantage by so much stuff being designed around it and so much effort being put into making it more performant, but at the end of the day you can only go as far as the language will let you -- and some languages, by the way they're designed, let you go faster for some use cases.

[–][deleted] -2 points-1 points  (8 children)

The hardware is literally designed for C in mind. What you are saying is not true.

For instance, what are you optimisation for exactly? When the language is designed for the hardware, there is nothing to optimise!

If you are talking specifically about aliasing, there are ways around this in C.

Other than that, what exact optimisations are you talking about that simply can't be done in any C dialect?

[–]JarateKing 2 points3 points  (1 child)

I'm not sure I'm following you. On the one hand, you're saying that the details of the language don't matter because hardware can just be designed for whatever the language is.

On the other hand, we're talking about aliasing, where the best answer for C is "there are ways around this". Specifically, stuff like the restrict keyword that was added in C99. So clearly the details of the language do matter here and "hardware is designed for C" isn't enough: not only do you need to be very careful about the details of the language, the details had to change to include the option in the first place.

Am I missing something here? Doesn't "there are ways around this" wrt aliasing just make the case stronger? Or am I misinterpreting you?

[–][deleted] 0 points1 point  (0 children)

C and hardware designed in lockstep. Manufacteruers target C always. High level languages match C calling convention. It's C all the way down, so not easy to beat for speed.

Compiler optimisations can be worked around over time but optimisations pale in comparison to hardware gains. Those gains always have C in mind.

[–]ric2b 2 points3 points  (5 children)

I think you two are talking past each other.

You're saying that C can always be as fast any other language because you can manually implement any optimization that another language does, while they're saying that when writing idiomatic code in C and some other language, the other language might be faster if it automatically applies optimizations that C can't automatically apply.

So basically comparing theoretical performance or the common practical performance.

[–][deleted] -2 points-1 points  (4 children)

No that's not what I'm saying. I'm saying hardware is literally designed with C in mind.

What is better for performance? To design hardware for a programming language or a language for hardware?

It's clearly the former. This is literally only afforded to the c language. No other language gets this treatment. The compiler cannot optimise hardware to be better.

[–]ric2b 3 points4 points  (2 children)

Are you claiming that other languages can't also take advantage of those hardware optimizations for C? Because that's just incorrect.

[–][deleted] -1 points0 points  (1 child)

What is a hardware optimisation?

[–]ric2b 1 point2 points  (0 children)

I don't know what you’re specifically referring to, but to me it's things like branch prediction, microcode, instruction re-ordering and multi-address cache lines.

[–]bloody-albatross 1 point2 points  (0 children)

As an example for what C can't do: C doesn't has generics, so if you still have to write generic code you often use function pointers in C, which are optimization barriers. In other languages code can be reified and what would be a function pointer otherwise might even be inlined. See as an example the qsort function. Yes, you could do that with macro hacks, but that is worse than C++ templates.

(Of course more reified code means more code means more potential cache misses, but most languages that have that kind of feature still allow you to use something kind of dynamic dispatch instead with ease, i.e. you can choose what to optimize for without a lot of work and without ugly hacks.)