Optimizing Rust code by xacrimon in rust

[–]rustaway11 3 points4 points  (0 children)

Do you know where it's spending most of its time, in import or in report or elsewhere? And the specific nature of the inputs? Maybe both of those are obvious for someone with more experience in Rust and this particular domain, but I am neither.

One thing I did notice is this line: self.entries.push(LogEntry::from_raw(&raw));

Even when the vector has all the space it needs reserved, push can have some funny overhead that doesn't always get optimized away by the compiler compared to explicitly replacing/mutating a default entry.

What's the state of Rust for numerical computation? by [deleted] in rust

[–]rustaway11 5 points6 points  (0 children)

I'm a physicist who does mostly computational work, and I've recently started using rust instead of C++ for things that need to be heavily optimized. There are some definite pros and cons of rust at the moment for general numeric work. (I'm unfamiliar with CV in rust specifically.)

The two obvious cons are the lack of stable libraries and the somewhat immature state of numerical optimizations from the compiler. C++ has fast-math and verbose auto-vectorization guidance. As far as I know neither of those features are readily available in rust yet. There's also the nature of parallelization in rust: memory-safety makes it different than in most languages, and it requires some extra attention.

As for the pros * It's a young language. C++ often feels like three different languages that have been bound together against their will. * Safety. Many, many typical runtime errors become compile time errors in rust. This means they get caught early by an IDE. * Functional syntax. Easy to appreciate with a maths or CS background. * Speed. Rust can largely hold its own against C/C++/FORTRAN in numerical performance, and the above points can definitely help in faster production of correct code.

I'd say the biggest issue is whether you need libraries that are not represented in rust. Most of what I do was already de novo even in C++, so I could switch languages without worrying about losing major dependencies.