by smegel · 14y ago · 0 comments
No-compromise performance still happens with C and C++. Secondarily Fortran and Ada for their respective industries. I doubt that'll change anytime soon as I'm not seeing any languages that are choosing the same priorities. Go isn't a systems language by any measure or estimation in design or implementation, and Rust is a type-safety-centric compromise that will likely end up somewhere around Java in performance. I'm not seeing much indication from the mailing list that safety-off all-go performance is a priority for the Rust devs because they seemed to favor avoiding the quagmire of a large C++ codebase.
I think realistically a "clean start" of C++ with the best of C++11 and earlier standards but removing a lot of the less worthwhile features would go a long way. Won't happen though. A lot of people avoid those problems by just writing C. Missing out on the cool reference counted pointers and compile-time stuff though.
Any language that wants to fully replace C/C++ has to embrace "pay only for what you use". Mandatory anything at runtime at the language design level is untenable.
"Pay only for what you use" sounds like a really great principle. But ...
Every user of C++ pays the cost (in convenience and reduced bugs) of not having automatic memory management, even if they don't need its benefits in memory consumption and avoiding GC pauses.
Many users of C++ pay a performance cost for the language's lack of automatic memory management, because getting the best performance from an automatic memory management system requires tight language integration and you can't have that with C++. (So they fall back on refcounting or Boehm-Weiser-like conservative GC, and pay the cost.)
Every user of C++ pays the cost (in ugly syntax and long compile times because of the included-header model) of backward compatibility with C, even if they don't really need that.
Many users of C++ pay a performance cost for this, because the C++ compilation model means that template-heavy code tends to end up with a lot of more or less duplicate object code, which means more cache misses and more time spent paging code in from disc.
Every user of C++ pays the cost (in overflow bugs and the like) of using integral types tied closely to the underlying processor architecture, even if they don't need the performance advantages it brings.
Some C++ users pay a performance cost for this, because if an application actually needs bignums then it'll typically be implemented using some general-purpose bignum system like GMP, which will typically perform very well for really large numbers but may be totally unsuited for smaller ones -- and sometimes most of the numbers you're computing with are in fact the small ones.
C++ uses "pay only for what you use" as a slogan, but it applies that slogan only in a very narrow domain. C++ users are paying, all the time, for lots of things they don't use. Quite a lot of C++ users are paying in performance for things they don't use. The slogan is misleading because it directs your attention to the obvious, explicit costs of features like automatic memory management and integer types that overflow gracefully, but there are plenty of costs that aren't so obvious.
(Lest I be misunderstood: For many applications C++ is a great choice. For some it's the only realistic choice. I am not, for instance, arguing that actually everyone should be programming in Common Lisp or something. I just think "you don't pay for what you don't use" is a really misleading slogan.)
Now that's just empty rhetoric. What about 'users of Java pay a performance cost for not having a stack, and creating every single object in the heap'?
I don't pay for unneeded garbage collection, and you can't use your rhetoric around it.
It is. We are counting every cycle in the JS<->Rust bridge, for example, when compared against C++ Gecko and WebKit.
As a general policy, Mozilla does not take performance regressions. Servo is a total non-starter if it is a performance regression over the existing C++ browser engines.
That said, Rust does some things by default that C++ doesn't do by default, such as stack overflow checks and array bounds checks. This is because we believe that, for most apps, they're the right defaults when weighed against the dire security consequences. It's planned for both of these to be able to be switched off in the future. (It's already possible to switch off array bounds checks, and switching off stack growth will be needed for competitive JS<->Rust interoperability in Servo.)
I really want real numbers, not idle conjecture. Gosling was fond of speculating that Java would eventually be faster than C and C++ because of $COOL_FEATURE_X, but nothing ever materialized or made enough of a difference.
Concurrent GC didn't make up the difference. JIT didn't make up the difference. Why would I believe anybody else bringing the same message?
This cyclical "we're gunna be faster and here is the cool compiler research saying so!" is why the programming language community has thoroughly alienated my colleagues that work in systems.
They can't afford to build their systems on speculation, it HAS to work. They believe nothing anybody says about programming languages now.
What's the most impactful territory to conquer that could help make up the difference?
Rust's design allows for a subset of valid programs that could be constructed in C++. It's the same kind of thinking that Haskell utilizes. The type system is useful in Haskell because it disallows potentially invalid programs giving you a smaller space to reason about. (cf. Total programming)
However, that subsetting means avenues and opportunities for optimization are eliminated. Optimization sometimes means doing something batshit.
A high-level 6502 emulator a friend wrote in x86 asm comes to mind.
Certainly, if you need something to be shipped soon, and you need it to be performance-competitive with C++, don't use Rust. Despite the fact that it's backed with LLVM, the compiler is quite immature.
I don't think at this point that any significant avenues for optimization are closed off in the Rust language design relative to C++. The safety checks are all designed to be optional.
Uhm, I'd say Java already is faster than C++ for all intents and purposes. If your codebase is >50KLOC and the number of developers on your team is more than, say, 4 or 5, then some crazy optimizations that are possible in C++ for small applications are out of the question, and the JIT plus the GC more than make up the remaining difference. Also, modern performance-critical software requires good concurrency, and Java has stuff like fork-join, that I'm not sure is available in standard C++ (it is, of course, available in Cilk).
So, even though it's hard to provide hard evidence (because most benchmarks are <50KLOC and written by one or two developers at most), I'd say from experience that Java already is faster than C++ in practically all circumstances (except, maybe, scientific-computation applications), not counting startup time. The only missing piece in the Java performance puzzle is value types and arrays-of-structs, and those, I believe are coming, and should make scientific-computation faster in Java as well.
It would've been more constructive for D to focus less on using GC and more on compromises and intermediate stages between fully static memory management and raw malloc/free.
Compromises like reference-counting pointers with various semantics available in Boost.
C++ didn't kill D, Java did. D was never going to replace C++.
Rust is doing a better job of making things like that available (unique pointer, borrowed pointer, etc).
That said, D didn't embrace "pay for only what you use" at a serious level because shutting off the GC basically left you in the wilderness and there weren't many accommodations made for making non-GC operation as good as possible. Rust doesn't seem to embracing that either for the sake of prioritizing safety.
Also, the GC in Rust is not for safety (as the language is memory-safe regardless of whether you use the GC); rather it's for convenience when you want it.
We can't ship a competitive touch-responsive browser engine if the compositor has GC pauses, so making the GC optional is as critical for us as it is for everybody else.
I'm sure the big players are in standard C++ for the long haul. Though, the thing you mention, wouldn't that make a good (though ambitious) community project? Make a hot-rod non-standard C++ implementation using Clang as a starting point.
Getting consensus on what to take out would be difficult, considering a lot of the features aren't there to incrementally improve the lives of 'everyone', but rather to cope with an edge-case that could be a fatal problem for something specific. That's how a lot of committee work goes.
I wouldn't mind seeing such a thing. I find C++ intimidating, but I don't think the answer is to completely forgo utilizing it. Realistically my solution is to only use features I understand in relation to how something similar would look in C.
Absolutely true. I don't understand people trying to use every single language feature in every single program. And I'm thinking in general terms, not just C++.
And what are those features, according to you?
Also, any C++ programmer making fun of Java should go and compare the syntax for HashMap<T> versus unordered_map(). Hash maps are probably one of the most widely used data structures and the C++11 implementation is much clunkier than Java's.
Many in the HPC community think anything that is not compiled is a joke.
As someone who works with a lot of Python/NumPy/SciPy, I can see how they'd come to that conclusion. Python's a great way to prototype, but a production runtime for high performance applications it is not.
Also, the intersection really good C++ programmers + domain specific knowledge is very small in general. I don't think that's where the world is going in general, honestly, except for some niches or areas where skilled human factor is cheap (e.g. academia).
My experience with repeatedly seeing claims like this in different contexts is that I'm not sure they've ever exceeded the performance of static binaries in pretty much anything.
They used to claim it for Lisp, then Java. I'm done waiting, I'd rather just use something I know can be made fast than hoping the PyPy guys do magic.
My point is that in certain scenarios where you need performance but aren't willing to pay the C++ grief, you can get away with better languages without significantly sacrificing.