
Rust is Not so Hairy - nevi-me
https://nevi.me/rust-is-not-so-hairy/
======
nevi-me
A few people asked me about my experiences with Rust after I mentioned seeing
significant performance improvements.

I wrote a blog post about it and open sourced both the Java and Rust code.

~~~
geezerjay
Thank you for writing the article. It's very interesting and a pleasant read.
Kudos!

~~~
nevi-me
Thanks! Someone suggested I also create the same with Go, I'm going to give it
a bash in the coming days.

------
majewsky
> Using protobufs meant deferring learning the various serde's of Rust, which
> has helped me to focus on getting something done.

I have only dabbled once with Serde to generate some JSON, but I found it
quite pleasant to use. Similar to Go's JSON library: You basically annotate
your types like "this struct can be serialized, the field FooBar is serialized
as 'foo'" etc., and Serde generates a serialize method for you (or, to be
precise, it generates an implementation of some Serialize trait for your
type).

~~~
nevi-me
It was less about JSON, but more about reducing the number of libraries that I
had to learn in one go. The benefit of using protobufs/gRPC was that I already
had a host of microservices that I could choose to interact with.

I'll need to learn serde at some point, but it might be after a while as all
the things I'm planning on doing with Rust include protobufs.

------
blackrock
// Mutable pointer to the field.

// If field is not initialized, it is initialized with default value first.

pub fn mut_message(&mut self) -> &mut ::std::string::String {

    
    
            &mut self.message
    

}

=========

Geez, this is ugly.

And here's another..

=========

// Take field

pub fn take_message(&mut self) -> ::std::string::String {

    
    
            ::std::mem::replace(&mut self.message, ::std::string::String::new())
    
    }

------
jokoon
Good performance is not surprising, it's a statically compiled language.

~~~
littlestymaar
Being “statically-compiled” isn't some magic property that automatically makes
program run faster. It can even be the opposite in some situations, since you
can't benefit from JIT optimizations.

What makes Rust, like C or C++, efficient is not just that they are statically
compiled, it's that they have massively-tuned optimizing compiler spending a
lot of time in compile-time optimizations.

If you take Go, another statically-compiled language, its compiler is way less
aggressive with optimization because the Go compiler developers wants to keep
the compile-time low (which is probably a good idea in their niche) and
because it has been much less of a focus than for LLVM or Gcc. As a result, Go
is slower than C/C++/Rust by almost an order of magnitude, despite being
statically compiled.

Another example: if you compile C code with `-O0` optimization level, it will
still be statically compiled, but it will be way slower than most JIT-ed
languages.

~~~
pjmlp
> What makes Rust, like C or C++, efficient is not just that they are
> statically compiled, it's that they have massively-tuned optimizing compiler
> spending a lot of time in compile-time optimizations.

Actually lots of money spend across compiler vendors in the last 30 years, and
UB abuse, as C compilers were pretty lame in the early 80's.

~~~
dbaupp
There was no need to "well actually" that, as it is the same point the parent
was making: that money (and UB abuse) is why the tuned compilers now exist.

~~~
pjmlp
I interpreted differently, as if being an inherent property of how C and C++
were designed.

