Live data from Hacker News

Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

risingwave-labs.com

101–110 of 307 posts

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#101

Earlier quoted context omitted.

I don't understand. Smart pointers replace dumb pointers not normal stack/inline object placement.

Yes, but people need to be aware that "auto obj = make_unique..." or "auto obj = make_shared..." should be a very rare thing and not the norm (and I've seen plenty code bases like that). There needs to be a proper memory management strategy with the goal of minimizing heap allocation in random places in the code. E.g. automatic memory management doesn't resolve you from thinking just as much about memory management t…

I would hope they are, otherwise why are you even writing C++. I might have too high expectations though...

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#103
post #33

Earlier quoted context omitted.

> However C++ smart pointers impose a run time performance penalty on your code. i'm not sure if this is the case. unique_ptr doesn't really do much other than use the type system to ensure that only one instance of the pointed-to value exists at once. as far as i understand, it doesn't strictly do anything at runtime.

unqie_ptr have overhead. It need to run its dtor etc. https://www.youtube.com/watch?v=rHIkrotSwcc At 18 min.

You're misinformed. Overhead is not about the running the dtor, unless you're willing to leak the memory in your code regardless of the smart ptr usage or not.

What the "overhead" of unique_ptr is usually attached to is the inability for a compiler to pass the unique_ptr as a value through a register but will instead have to use the stack (memory). And that even doesn't apply in the general case but _only_ for unique_ptrs holding an object with non-trivial copy-constructors or non-trivial destructors. This is due to the platform ABI and not the C++ compiler limitation.

Anyway, calling that an overhead is a far stretch and almost purely theoretical unless someone is able to measure the negative effect of such code transformation in the real-world codebase. And I say this as not particularly heavy user of smart pointers.

Also, many other codegen transformations will not fit into a very limited amount of ABI registers so should we argue about not using those as well?

In my opinion, this was only a "campaign" of Google trying to use a unique_ptr as a leverage to persuade the committee to accept their break-the-world ABI suggestion. We know how it all went.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#104
post #98

"So, using C++ was a no-brain decision." Oooff.

The expression "no brainer" means that some decision is so obvious as to not require any thought. I think this article is saying that using C++ with a team of seasoned C++ developers was such an obvious thing to do that they didn't give it much thought.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#105

Fascinating how defensive C++ lifers can be. Rust builds on the knowledge of decades of C++ programming. It’s basically a compiler enforced set of C++ best practices. It’s strange how hostile some in the C++ community are to Rust.

I could be wrong, but I think there's few big camps of people.

The camp that thinks Rust is just unnecessary fuss because "you can do it all" in C++ already. They pride themselves with knowing C++ esoterica, and don't like that Rust lowers the entry barrier to writing similar software. They want an exclusive club. They also see ownership as a nuisance. They know you can be equally reckless in Rust too, but they don't like that Rust is so "in your face" about it, too.

The camp that is afraid Rust will marginalise C++ and hence push them towards undesirable (even if high paying) jobs.

There's the camp that's jaded by seeing too many fads come and go, and probably just burnt out at some point. So, they just want to work with what's there and be left alone. They don't want to learn something that they know (incorrectly or not isn't for me to judge here) will be dead in the water soon. And they'll have wasted their energy on it for naught. Or in short, they see it as an unwelcome distraction. This camp also includes "but it has no ISO specification for aviation/etc" too.

I think all these are wrong.

I don't think C++ will be marginalised, it just won't be the default choice for certain domains.

I don't think the extra tooling is a nuisance, if anything in my experience it unburdens the mind from non-domain concerns.

And I also don't think it's a fad, given how productive the language makes people feel, and the fact the Rust Foundation is very serious about the longevity of the project, and that it has many big-player backers.

There's also obviously others too; people come in about 8 billion flavours.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#106

Fascinating how defensive C++ lifers can be. Rust builds on the knowledge of decades of C++ programming. It’s basically a compiler enforced set of C++ best practices. It’s strange how hostile some in the C++ community are to Rust.

You have to remember that we die. So what you learn til 30, say, you capitalise on till 70, and then you retire & die.

There isn't another live to live until 30 "again", and then be within the Rust culture.

Rust has, by analogy, stapled it's "Ninety-five Theses to the door" of C++ and those C++atholics are afraid their way of life is ending before they do.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#107

Earlier quoted context omitted.

In my experience, segfaults are often a result of using C libraries in C++. In the project I work on, OpenSSL integration supplies a constant trickle of segfaults (it's not my general area, I'm just witnessing those and report to whoever works on it). This is especially true if you are trying to use those libraries in multi-threaded environment.

Segfaults happen, you run valgrind/asan/tsan etc. As long as the codebase is not horrendous its easy to fix. Third party packages complicate things, have to choose/use wisely/appropriately

In Rust they are really rare. Like vanishingly small numbers of them. C++ definitely. SegFaults happen. Sometimes they are even in prod. Rust not so much.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#108

> But as more and more engineers joined us, some shortcomings > of C++ came to bite us: unreadable coding style, memory leak, > segmentation fault, and more. * unreadable coding style: This is not a C++ problem. * memory leak: Memory leak is an old C++ problem, since C++11 there is no reason for not using smart pointers. The only point that could be attributed to C++ is the segfaults perhaps, due to its lack of safet…

I’ve worked on quite a few codebases over the years. Only two were of outstanding quality and robustness. One was Java. The other was C++.

What both of those had in common was a single strong tech lead that would veto code with no argument if it didn’t meet standards.

I’ve yet to work on Rust but I’ve seen horrific and buggy code in C++, C, Java, Kotlin, C# and of course JavaScript and Python.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#110

Earlier quoted context omitted.

> since C++11 there is no reason for not using smart pointers. Smart pointers lure you into a dark alley where each tiny object lives in its own tiny heap allocation, and before you know it you have so much memory management sprinkled decentralized all over your code base that the memory management overhead becomes a performance problem, but at the same time it's too late to do anything about it because it would mean…

I don't understand. Smart pointers replace dumb pointers not normal stack/inline object placement.

It's not about what you use to point to the thing. It's about how you allocate the thing in the first place. Smart pointers are like a free pass to do things without consideration: they allow you to make progress without caring how your things are allocated, because they ease the pain that results from just allocating stuff on the global heap, lacking a systematic approach.

Note that while smart pointers ease pain in the short term, there are subtle complications that arise from the constraints that they introduce. One is performance, in some cases the cost of generalized memory management can be too much. Memory fragmentation can be an issue too. RAII the mechanism is not free but requires compatible code and containers. I'm sure there are lots of projects that have broken under the added constraints introduce by such smart classes.

And while smart pointers are orthogonal to systematic memory management, if you get the management right the use of smart pointers can easily become a net negative.

Post reply on HN