6 ms·
Rust looks very exciting and promising. I see the hardest things for it to be not necessarily syntax and concurrency (which are very well done), but performance
by rdtsc 13y ago
Rust looks very exciting and promising. I see the hardest things for it to be not necessarily syntax and concurrency (which are very well done), but performance and getting to compete with C++11 (C++14), which actually seems to become fresh and interesting again.
Performance is tough. I feel most often C++ is not chosen for its inherent cleanliness, elegance and beauty, but because there are no viable competitors at the given performance point. C++ compilers have been honed and tweaked for more than a decade now, so it will be a hard battle ahead.
- pcwalton 13y agoI feel pretty good about it. For one, we have significantly better aliasing information than C++, and we use most of the guts, including all the optimizations and code generation, of a C++ compiler (clang/LLVM). There are also some optimizations around move semantics that are open to us but not for C++ as standardized. That said, there are definitely performance bugs that have yet to be fixed. But I would definitely say most Rust code, if well-written, can be competitive with C++ today.
- seertaak 13y ago> There are also some optimizations around move semantics That piqued my curiosity -- would you mind going into a little more detail, or point me to somewhere where these are discussed?
- pcwalton 13y agohttps://github.com/mozilla/rust/issues/5016 https://github.com/mozilla/rust/issues/5016 is the main optimization (and we have more discussed but not written up). Since we have a very strict notion of liveness, we don't have to zero out moved data since the compiler can just not run the destructor.
- berkut 13y agoHow does one do intrinsics (SSE / AVX) in Rust - I guess they're just the exposed functions from emmintrin.h and the compiler calls them directly? How do you do ASM in Rust? Can you align memory in rust?
- masklinn 13y ago> How do you do ASM in Rust? There's an asm! macro: http://static.rust-lang.org/doc/0.10/guide-unsafe.html#inline-assembly http://static.rust-lang.org/doc/0.10/guide-unsafe.html#inlin... > Can you align memory in rust? I think that's an open problem for now, e.g. https://github.com/mozilla/rust/issues/4578 https://github.com/mozilla/rust/issues/4578
- berkut 13y agoAligning memory is pretty important for high-performance apps using SSE/AVX (archs after SB don't need alignment any more, but still benefit from it) - and generally anyway - cacheline alignement, etc, and while it's often possible to force structs / classes to be aligned by padding them, this doesn't always work. Does Rust allow using memory allocated by specific external allocators? i.e. libnuma or something?
- masklinn 13y ago> Aligning memory is pretty important for high-performance apps using SSE/AVX Er… yes? Did I say it was unimportant anywhere? (also please note that I'm not a Rust developer) > Does Rust allow using memory allocated by specific external allocators? i.e. libnuma or something? I'm not quite sure what you're asking * if you're asking if it's possible to use arbitrary memory returned by a third party? Then yes. * if you're asking whether user-defined allocators or boxes are supported and you can ask the runtime to put its stuff in memory you get from e.g. a bundled jemalloc, then that's planned but not in I believe: https://github.com/mozilla/rust/issues/12038 https://github.com/mozilla/rust/issues/12038
- berkut 13y ago> Er… yes? Did I say it was unimportant anywhere? No, but that link seemed to indicate it wasn't being planned for the first release and pcwalton seems to think it's possible to get Rust programs to run as fast as C++ programs in most cases.
- NAFV_P 13y ago> Performance is tough. I feel most often C++ is not chosen for its inherent cleanliness, elegance and beauty, but because there are no viable competitors at the given performance point. I don't think there are many popular high level languages that target systems programming in the first place.
- pjmlp 13y agoThe problem was the trend in the mid-90's to move away from native AOT compilers to VM JITs, thus leaving C and C++ as the main to go languages most mainstream developers know, as other options faded out of sight. Hopefully the "going back to native" trend will move us back on track, similar to how it happened in the early 80's VM attempts.
- twic 13y agoI think the real problem is the move from manual memory management to garbage collection. Garbage collection has immense advantages, and is indisputably the right choice for most application programming, but it only goes fast if you feed it lots of memory. See figure 3 of this wonderful but terrifying paper: http://people.cs.umass.edu/~emery/pubs/gcvsmalloc.pdf http://people.cs.umass.edu/~emery/pubs/gcvsmalloc.pdf (Caveat: that was published in 2005, and garbage collection has improved since then. However, i doubt it has improved enough to invalidate its conclusions.) The best collector there needed ~3x as much memory as a (admittedly superhumanly perfect) manually memory management to get to a competitive speed. There are plenty of problems where that memory is available. But there are plenty where it is not. I can justify giving loads of memory to the application that makes my company money. I can't justify giving it to some tiny little log shipper or message forwarder or other random system utility that i want to run on every machine in my infrastructure.
- pjmlp 13y agoWhat does it have to do with VMs, though? There are lots of languages with native code generation compilers that have GC[1] support. Since the Xerox PARC days there have been system programming languages with automatic memory management (Cedar, Interlisp, Modula-3, Oberon, ....). They were just ignored by the mainstream OS vendors, that were busy creating UNIX System V and VMS clones. [1] RC is usually GC chapter 1 in CS books.
- Pxtl 13y agoNobody will ever beat C/C++ for raw soft-real-time speed. Even a language like Rust that may have the linguistic features to be blazingly fast will never close that massive gap in historical optimization. Rust will never have an Intel-compiler. That said, Rust will get close to C/C++ in ways that GC-based languages never will. GC languages mean memory bloat and soft-realtime problems related to GC cleaning. It will likely hit the sweet spot for a lot of embedded or gaming uses. Obviously you can do those tasks in other languages (great stuff is done on phones with GC-based languages, obviously), but you have to work around some challenges that would not exist in Rust.
- kam 13y ago> Rust will never have an Intel-compiler. Yesterday, Intel announced a project combining a clang frontend with icc's backend. [1] The backend takes LLVM IR, so hopefully Rust's LLVM IR output could be run through it. [1] https://news.ycombinator.com/item?id=7663462 https://news.ycombinator.com/item?id=7663462
- loup-vaillant 13y ago> Even a language like Rust that may have the linguistic features to be blazingly fast will never close that massive gap in historical optimization. Rust will never have an Intel-compiler. That's most probably false: the current self-hosting implementation have an LLVM backend. So it has back end optimisations covered. As for the front end, Rust's cleaner semantics will make many optimizations easier. Plus, it's not like the historical gap couldn't be closed by reading the gazillion papers on C++ optimization out there. Copying a known technique is much faster than developing it in the first place. Maybe Rust will end up slower than C++ anyway, but it won't be the compiler's fault.
- malkia 13y agoWell, it's already been beaten on most common hardware, though not fairly and not on the same "cpu" chip, but on the gpu: OpenCL, Cuda, DX/GL Shaders. Can't beat that (yet)! there exist some fairly minimal "C++" like languages for gpu, but nothing to fully deal with strings, exceptions, STL, etc. And then there is FPGA, but probably not a fair mention since these do not exist (in general) with most common hardware (pc computers, phones, pads, etc.) - while GPU's are found almost anywhere, and on most of the devices now, one can exploit extra computing power exactly by using the GPU.
- loup-vaillant 13y ago> I feel most often C++ is not chosen for its inherent cleanliness, elegance and beauty, but because there are no viable competitors at the given performance point. My feeling is that most often, (i) people don't need nearly as much performance as they think, and (ii) they greatly overestimate the performance gap between C++ and garbage collected languages (most notably those who are compiled to native code, such as Lisp, ML, and Haskell).
- pohl 13y agothey greatly overestimate the performance gap between C++ and garbage collected languages I think you're right about that, but I also think that people greatly underestimate the determinism gap between them, too. (Not necessarily the same set of people, of course.)
- loup-vaillant 13y agoI'm not sure. If you start using smart pointers in C++, you can get the same problem: instead of a GC pause, you get a cascading delete pause. To eliminate it, you have to devise a smarter memory scheme, at which point you probably don't underestimate the determinism cap. Also don't forget that garbage collectors can often be tuned. Granted, many of them suck, but a generational, incremental collector whose parameters can be tweaked? Much less room for pauses.
- AnimalMuppet 13y agoThere are few viable competitors that: - give access to as low a level as you need, in a way that you can tell what the costs of various actions are going to be, - lets you manage different pools of memory differently, - lets you use higher level abstractions (clear up to lambdas), - gives you confidence that it will still be around in a decade or two (I have worked on code bases that lasted two decades), and that coders will still be available in that language. It's not just the performance point. It's how well it's known. (Including how well the flaws are known. What's wrong with C++? Plenty, but there are people who know how to work around it. What's wrong with Rust? Presumably a fair amount as well, but we don't know what yet.) It's how mature our understanding is of how to build million line code bases that can be maintained for decades. And, sure, people are going to scream about the memory bugs that are going to make that million-line code base a maintenance nightmare for decades. But what's going to make a Rust program a maintenance nightmare for decades? (Don't bother trying to tell me it won't be one.) You don't know. I suspect, however, that there is at least some danger that you won't be able to find many Rust programmers two decades from now. tl;dr: C++, for all its flaws, is pretty well understood. We know that we can build at-least-somewhat-working large programs and maintain them for decades using it. We know of few other languages where that is true.