What kind of performance rust is trying to achieve?


#1

Reading the homepage and other links on the web say that rust is very performatic, don’t have gc, has zero cost ffi, …

But, what is the performance goal in rust, have the same speed as c? 10% faster? 10% slower?

Im working in a project where performance is the key metric, we need to analyse gbs of network traffic and so, we need the fastest language possible (excluding asm :stuck_out_tongue:)


#2

Rust prioritizes memory safety above all else. But speed is a close second.

Generaly, it’s ‘the same order of magnitude as C’. Sometimes faster, sometimes slower.


#3

Rust is certainly plenty fast as of today. However, there are areas where C may be able to achieve better performance for various reasons.

we need the fastest language possible

This very much depends on what you’re trying to achieve. If you do a lot of number crunching, I could perhaps interest you in some fortran? It’s not your granddaddy’s language anymore. C and C++ are quite capable all-round languages, which offer enough rope to hang yourself, but are still not without reason the workhorses of the industry. I know a few people from the high-frequency-trading domain that have made good experiences (and fortunes) using Java. Rust is a newcomer language, and while it makes good use of LLVM optimizations, it has some unoptimized places yet (e.g. some regexes may be quite slow).

If I would start a completely new project (and had no company policy mandating java), I would bet on Rust, profile the living hell out of the bottlenecks and if necessary rewrite the hottest loops in C.


#4

I don’t have any restriction on language and yes, its a new project.
About the project, isnt really a computacional problem like in fortan programs, is more c/c++/java thing.

But thanks, gonna give a try to rust. I also really want to go in this low level world.


#5

In the long run, I think Rust will be faster than C and C++ for a few reasons:

  • Much stronger aliasing guarantees; look at the optimizations Fortran compilers can do.
  • Ability to do so much fancy stuff at compile time, including specializing code to its exact use case. Whenever you see a C API that has a struct of function pointers, or a C++ class with virtual methods, that’s basically the equivalent of a Rust trait object, i.e. dynamic polymorphism. Rust gives you that option but you can also use the same interfaces (traits) for static polymorphism. C++ supports static polymorphism via templates, but it’s a completely different world with ad hoc specification of interfaces. Macros are another good example; we have lots of compile-time computation in Servo to make things super fast at runtime. In C/C++ you might hack up a codegen script but you often wouldn’t bother. This stuff will be much better once Rust has integer generics, variadic generics, and compile time function evaluation.
  • A specific example that’s already true today: C++ std::vector must laboriously call the move constructor for every element when resizing, whereas Rust Vec will either resize in place or do a simple memcpy.

#6

All good points. Not to forget, where Rust really shines is fearless concurrency. This is one of the things that enable e.g. servo to pursue concurrent operations much more aggressively than in C or C++, backed by the guarantees the borrow checker affords them.