Live data from Hacker News

Why Rust for Low-Level Linux Programming?

groveronline.com

211–220 of 231 posts

Re: Why Rust for Low-Level Linux Programming?

#211

I love C, but I think we really have to stop building all kinds of shared libraries in C. Important code which needs to be secure and solid can't be built on C anymore, it puts everybody at risk. Just look at the disaster OpenSSL has been. I think Rust would be create for building common crypto infrastructure and things such as crypto currency. It seems risky to me to build something like Bitcoin with C++ where milli…

You are missing one very important point: bindings. You can bind to C from basically every other language, which is quite important for shared libraries.

You can expose Rust code as 'C' libraries and bind to them.

Re: Why Rust for Low-Level Linux Programming?

#212

Earlier quoted context omitted.

Rust can use simd too. It doesn't in those benchmarks. Please apply the common sense you keep harping about. Claiming rust is 2x slower because of that benchmark is a falsehood. Re:regex: my point exactly . Most microbenchmarks are prone to slight differences in the implementation causing issues (and you can rarely translate code exactly , especially to something like rust which often requires a different structure o…

> Rust can use simd too. No it can't. Either accept that the nightly build of Rust is not the Rust we are talking about or stop discussing with me. > Re:regex: my point exactly. The problem with regex libraries are that they are to big so therefore doesn't reveal so much about inherent language performance. > Most microbenchmarks are prone to slight differences in the implementation causing issues (and you can rarely…

What's nightly in Rust today will become stable soon enough (idk the timeline for SIMD). But OK. Stable only. In that case, rust is 2x slower than c code that can be optimized by SIMD. Not much of an issue, really, and it proves nothing about rusts overhead except that you can't rely on autovectorization. Not really a big deal.

> 19% is a huge difference.

IMO that in the realm of microbenchmarks, it really isn't. You clearly disagree, not much I can do about that.

> That C code isn't well-optimized at all...

Go ahead and fix it then. You've been telling me much the same. I already mentioned that the other benchmark you linked me to wasn't optimized.

> Does that mean it is impossible to prove to you that C is at least 2x faster than Rust since twice is less than one order of magnitude

I use the term loosely, 2x is certainly alarming. As long as you rely on simd benchmarks I will disagree though, since in most cases a lack of that optimization isn't the reason your program is slow. If you really really care about performance, use nightly rust; there's no cost to that. I have yet to see production C code that uses SIMD everywhere possible, just in some tight loops. That is not going to create a 2x difference in performance unless the tight loop dominates all else. That is not most use cases.

Re: Why Rust for Low-Level Linux Programming?

#213

Earlier quoted context omitted.

Rust can use simd too. It doesn't in those benchmarks. Please apply the common sense you keep harping about. Claiming rust is 2x slower because of that benchmark is a falsehood. Re:regex: my point exactly . Most microbenchmarks are prone to slight differences in the implementation causing issues (and you can rarely translate code exactly , especially to something like rust which often requires a different structure o…

> Rust can use simd too. No it can't. Either accept that the nightly build of Rust is not the Rust we are talking about or stop discussing with me. > Re:regex: my point exactly. The problem with regex libraries are that they are to big so therefore doesn't reveal so much about inherent language performance. > Most microbenchmarks are prone to slight differences in the implementation causing issues (and you can rarely…

Oh, and transliterating C and C++ is an exception to the norm. C and C++ are historically linked and quite similar in many ways. Rust does not have this relationship with C. You could easily transliterate C code to unsafe rust code, but that sort of misses the point, doesn't it? :)

Re: Why Rust for Low-Level Linux Programming?

#214
post #177

Earlier quoted context omitted.

Or how about we avoid the whole thing and allow multiple versions of a lib to exist, and then prune the branches as they are no longer needed? Something akin to Nix/guix, Gobolinux, or even GNU Stow.

C and C++ libraries can use ELF symbol versioning. Say you have a function like int foo_do(struct foo *, int); but to fix a bug and/or tweak the API you change it to long foo_do(struct foo *, int, int); then ELF symbol versioning allows you to do __asm__(".symver foo_do_v1_1,foo_do@@v1.1"); long foo_do_v1_1(struct foo *F, int arg1, int arg2) { ... } __asm__(".symver foo_do_v1_0,foo_do@v1.0"); int foo_do_v1_0(struct f…

Interesting, I had no idea the C runtime on Windows is not forward or backward compatible.

I'm curious about your thoughts on why the "recompiling and bundling dependencies" approach might not be the best way compared to ELF versioning facilities? Do you just feel like its a less elegant solution?

Thanks

Re: Why Rust for Low-Level Linux Programming?

#215

Earlier quoted context omitted.

> Rust can use simd too. No it can't. Either accept that the nightly build of Rust is not the Rust we are talking about or stop discussing with me. > Re:regex: my point exactly. The problem with regex libraries are that they are to big so therefore doesn't reveal so much about inherent language performance. > Most microbenchmarks are prone to slight differences in the implementation causing issues (and you can rarely…

What's nightly in Rust today will become stable soon enough (idk the timeline for SIMD). But OK. Stable only. In that case, rust is 2x slower than c code that can be optimized by SIMD. Not much of an issue, really, and it proves nothing about rusts overhead except that you can't rely on autovectorization. Not really a big deal. > 19% is a huge difference. IMO that in the realm of microbenchmarks, it really isn't. You…

> Not much of an issue, really, and it proves nothing about rusts overhead except that you can't rely on autovectorization.

Not much of an issue unless you actually need the performace ofcourse. Ime, simd intrinsics is everywhere in code optimized to run as quickly as possible on x86. That about half of The Benchmark Game's benchmarks uses sse proves that point.

> Go ahead and fix it then. You've been telling me much the same. I already mentioned that the other benchmark you linked me to wasn't optimized.

That requires investing a lot of time in understanding how Ruby's internals and especially its string objects works. I don't have that time. The LPathBench on the other hand is self-contained and updating it shouldn't be more than a few hours of work for a decent Rust programmer.

Re: Why Rust for Low-Level Linux Programming?

#216

Earlier quoted context omitted.

Ah neat, I did not know about the book, thanks.

No worries. I'm currently in the process of re-writing it for the second edition...

Would it be worth including a chapter(s) on writing Linux system utilities using Rust?

I hope you announce it on HN when the rewrite is finished.

Re: Why Rust for Low-Level Linux Programming?

#217

Earlier quoted context omitted.

What's nightly in Rust today will become stable soon enough (idk the timeline for SIMD). But OK. Stable only. In that case, rust is 2x slower than c code that can be optimized by SIMD. Not much of an issue, really, and it proves nothing about rusts overhead except that you can't rely on autovectorization. Not really a big deal. > 19% is a huge difference. IMO that in the realm of microbenchmarks, it really isn't. You…

> Not much of an issue, really, and it proves nothing about rusts overhead except that you can't rely on autovectorization. Not much of an issue unless you actually need the performace ofcourse. Ime, simd intrinsics is everywhere in code optimized to run as quickly as possible on x86. That about half of The Benchmark Game's benchmarks uses sse proves that point. > Go ahead and fix it then. You've been telling me much…

> Not much of an issue unless you actually need the performace ofcourse. Ime, simd intrinsics is everywhere in code optimized to run as quickly as possible on x86. That about half of The Benchmark Game's benchmarks uses sse proves that point.

My point is that the Benchmark Game is not representative of real world code. The website says as much. Because the benchmarks use sse everywhere does not mean that most code, even perf-sensitive code will use simd everywhere.

Again, if you need simd, use a nightly. There's little to no drawback there.

I fixed it up to run on modern rust (https://gist.github.com/Manishearth/5fc73c405641162f0712951c..., compile with cargo build --release), and the numbers I get are:

(Ranges are just what I got from 5 runs, nothing scientific)

Rust: 610-630

c: 706-716

c_fast: 919?

cpp_clang: 669-694

cpp_plain: 717-728

I'm on a new (i7, 16gb) Mac so I don't yet have g++ around (nor do I know how to obtain it without messing things up; I'm used to linux), everything here done with clang.

Of course, this isn't an indication that Rust is faster than C. But it is an indication that it can be just as fast, and a reinforcement of my point about microbenchmarks having large error bars.

Edit:

On my older x86 linux laptop (with gcc):

Rust: 844-987

c_fast: 808-860 (perhaps clang somehow made c_fast slower than c on the mac? shrug)

c: 982-1025

cpp_plain: 977-1019

cpp_gcc: 925-947

I think I've proven my point.

Re: Why Rust for Low-Level Linux Programming?

#218

Earlier quoted context omitted.

> some modicum of common sense when reading the numbers on The Benchmark Game yes, this involves checking what the benchmarks are actually measuring. In this case, it is how much faster SIMD makes things. Factor that in, or rewrite the programs with SIMD in rust, and it should come out to be the same. > But it appears that it have. Have you not been listening? It doesn't. The speed differences you quote are due to si…

Using the nightly builds of any programming language in production is insane. That's why we call it FutureRust to differentiate it from what is production ready Rust. That Rust might have SIMD intrinsics in the future matters little to people trying to seriously use Rust today. And in several benchmarks C handily beats Rust even without intrinsics. Such as the fannkuch-redux one where it is about 2x faster.

[deleted]

Re: Why Rust for Low-Level Linux Programming?

#219

Earlier quoted context omitted.

> some modicum of common sense when reading the numbers on The Benchmark Game yes, this involves checking what the benchmarks are actually measuring. In this case, it is how much faster SIMD makes things. Factor that in, or rewrite the programs with SIMD in rust, and it should come out to be the same. > But it appears that it have. Have you not been listening? It doesn't. The speed differences you quote are due to si…

Using the nightly builds of any programming language in production is insane. That's why we call it FutureRust to differentiate it from what is production ready Rust. That Rust might have SIMD intrinsics in the future matters little to people trying to seriously use Rust today. And in several benchmarks C handily beats Rust even without intrinsics. Such as the fannkuch-redux one where it is about 2x faster.

Don't use the latest nightly then. Use the nightly from 4 months ago that corresponds to today's stable, ensuring that it doesn't have any extra soundness patches that need backporting. Usually the case.

I don't see "several", I just see one. Most of the non-simd benchmarks have almost exactly the same numbers for Rust and C. Perhaps the Rust test for fannkuch isn't optimized yet (looks like the C one has some extra logic about how to split up the chunks, whereas Rust blindly parallelizes)? I already optimized one Rust program, I'm not going to sit and optimize every benchmark out there -- we have tons of counterexamples of fast benchmarks already. It seems like you won't agree as long as one nonoptimized benchmark exists. In that case, good day to you. I'm done here.

Re: Why Rust for Low-Level Linux Programming?

#220

Earlier quoted context omitted.

No worries. I'm currently in the process of re-writing it for the second edition...

Would it be worth including a chapter(s) on writing Linux system utilities using Rust? I hope you announce it on HN when the rewrite is finished.

I don't want to put Linux above other platforms by only including it. And it's already a huge task on its own.

I will for sure. It's also going to end up getting published by No Starch.

Post reply on HN