Live data from Hacker News

Making Rust as Fast as Go

christianfscott.com

151–160 of 211 posts

Re: Making Rust as Fast as Go

#151

Earlier quoted context omitted.

> Since many programs don't need to do any kind of unicode segmentation, making it part of the standard library sounds like a bad idea. In particular, given that unicode is a moving standard, it would mean that people stuck on old Rust toolchains (e.g. LTS linux distros) cannot create binaries that do proper unicode segmentation, which does not make sense. That has nothing to do with it. You could still have a librar…

> It does not make sense either to expect someone to use bleeding edge libraries from cargo yet use an old rustc compiler. Of course it does. Many software users are stuck on multiple-year-old toolchains for various reasons, yet these systems still need to be able to handle unicode properly. > They can easily update it if needed. No, they cannot. Many users are stuck in older windows versions, linux versions, LTS lin…

IMO it's not as clear-cut as you make it out to be. It's a pretty arbitrary line to exclude full Unicode support from the standard library. There's a ton of stuff in libstd that could be supported as third-party crates. I don't disagree with what the Rust team has done, and I think there could be a world in which the compiler team also releases first-party crates with "enhanced" functionality beyond just libstd. I consider proper Unicode support to be a "first party" thing, but I also don't think it has to be in libstd per se, necessarily.

For the record, I also disagree with your assertion that "easily done in rust" should be extended to include "...by importing a third-party framework." In that sense anything is easy to do in any language where a third-party framework exists. I'm confident it's just as easy in go.

Re: Making Rust as Fast as Go

#152

Earlier quoted context omitted.

It's cheap, but not _that_ cheap. It shouldn't be as cheap as just iterating over a sequence of 32-bit integers. But yes, I did benchmark this, even after reusing allocations, and I can't tell a difference. The benchmark is fairly noisy. I agree with your conclusion, especially after looking at the input[1]. The strings are so small that the overhead of caching the UTF-8 decoding is probably comparable to the cost of…

> It shouldn't be as cheap as just iterating over a sequence of 32-bit integers. I wonder if there are any benchmarks about this? Specifically, it feels like in theory iterating utf8 could actually be faster if the data is mostly ascii, as that would require less memory bandwidth, and it seems like the computation is simple enough for memory to be the bottleneck (this is a wild guess, I have horrible intuition about…

If all you need to do is validate UTF-8, then yes, mostly ASCII enables some nice fast paths[1].

I'm not a UTF-8 decoding specialist, but if you need to traverse rune-by-rune via an API as general as `str::chars`, then you need to do some kind of work to convert your bytes into runes. Usually this involves some kind of branching.

But no, I haven't benchmarked it. Just intuition. A better researched response to your comment would benchmark, and would probably at least do some research on whether Daniel Lemire's work[2] would be applicable. (Or, in general, whether SIMD could be used to batch the UTF-8 decoding process.)

[1] - https://github.com/BurntSushi/bstr/blob/91edb3fb3e1ef347b30e...

[2] - https://lemire.me/blog/2018/05/16/validating-utf-8-strings-u...

Re: Making Rust as Fast as Go

#153
post #92

Earlier quoted context omitted.

Part of the problem may be they re-implemented `std::cmp::min` at the bottom of the file, I wonder if there's a more optimized version in the stdlib.

One of the most frustrating parts of rust (for me), is that `std::cmp::min` (and some other methods) require that their arguments are `Ord` (totally ordered), and floats are only partially order because of NaN, so you can't use std::cmp::min on floats.

That’s what https://doc.rust-lang.org/std/primitive.f32.html#method.min is for

Re: Making Rust as Fast as Go

#154
post #141

Earlier quoted context omitted.

"damaging the American public's faith" - Really, just the American? You ever realize there are other human species on this planet?

That's a fair criticism if clumsily put. For the record, I'm Canadian, British and Polish. I called out America as by far the biggest perpetrator at the moment. So to address the second half of your post, I have indeed heard of "other countries" (just ask USCIS) although being a US resident at the moment I want to speak to what I know, not for anyone else. Though if we're being super pedantic, there's only one human…

"That's a fair criticism if clumsily put" - I guess the original point was a shining example of elegance.

USCIS - the same organ that asks women "have you ever been a prostitute" on citizenship tests?

"Though if we're being super pedantic, there's only one human species on this planet -- species of course being defined as animals who can mate and produce viable offspring."

You got me here ;)

Re: Making Rust as Fast as Go

#155
post #154

Earlier quoted context omitted.

That's a fair criticism if clumsily put. For the record, I'm Canadian, British and Polish. I called out America as by far the biggest perpetrator at the moment. So to address the second half of your post, I have indeed heard of "other countries" (just ask USCIS) although being a US resident at the moment I want to speak to what I know, not for anyone else. Though if we're being super pedantic, there's only one human…

"That's a fair criticism if clumsily put" - I guess the original point was a shining example of elegance. USCIS - the same organ that asks women "have you ever been a prostitute" on citizenship tests? "Though if we're being super pedantic, there's only one human species on this planet -- species of course being defined as animals who can mate and produce viable offspring." You got me here ;)

If I'm understanding you correctly you're referring to the eligibility criteria at the back of an Adjustment of Status petition, form I-485, which is part of the green card process.

I'm pretty sure the prostitution questions apply to men, too. The question is "Have you EVER engaged in prostitution or are you coming to the United States to engage in prostitution?" (Part 8, Question 35). Credit where due, I suppose, an (albeit small) win for gender equality.

As an aside, you should see what else they ask. That's among the least concerning question -- they ask everyone if they've committed war crimes or trafficked humans recently, or been a member of a communist or nazi party. Or committed any political assassinations (Part 8, Question 48.a).

[1] https://www.uscis.gov/i-485

Re: Making Rust as Fast as Go

#156
post #66

Earlier quoted context omitted.

Go’s pathological NIH syndrome does come with downsides. For example, there was an infamous memory corruption bug in the way they called into vDSO.

> Go’s pathological NIH syndrome does come with downsides. Yes. And you can add the inability to use the glibc's nss modules under Linux. Making it unable to use sssd properly and authenticate a posix user on a machine with LDAP authentication. Getting completely independent from OS sys lib has consequences

This is not accurate. [1]

When compiled on Linux for Linux, Go will use libc and natively call NSS.

When cross-compiling to Linux from another system, Go requires (mostly) CGO to be disabled and a subset of NSS will be implemented in Go. Native NSS modules will not work.

[1] https://github.com/golang/go/issues/24083

Re: Making Rust as Fast as Go

#157

Hey all, as some keen-eyed commenters have pointed out, it looks like the rust program is not actually equivalent to the go program. The go program parses the string once, while the rust program parses it repeatedly inside every loop. It's quite late in Sydney as I write this so I'm not up for a fix right now, but this post is probably Fake News. The perf gains from jemalloc are real, but it's probably not the alloca…

Thanks for following up. Just as an FYI, there's a few bugs in your implementation, the most obvious one is the use of ".len()" in a number of places interspersed with ".chars().count()". These two return different values. ".len()" returns then number of UTF-8 bytes in the input string, which for ASCII is the same as ".chars().count()" obviously, but if you do attempt any Unicode characters, your function won't work.…

(related to the unrelated part) what if the media is corrupt? I mean, independently on current events (I really don't want to enter that here) we do live in a world where very few amoral corporations own most of the media industry.

If we (correctly) rely on the media to bring to public attentions relevant facts (both criminal and non-criminal) and keep a watchful eye on the nation who then keeps a watchful eye on the media?

is the model entirely based on always being there enough good journalist to spot the bad ones? how is this affected by the very precarious economics of current internet ads-based venture-funded media enterprises?

I just blurted too many questions... what I am trying to say is that similarly with the police there is not as easy answer in shoud-trust should-not-trust (in the US a supreme Court judge advised to "not talk to the police").

in that case I guess part of the problem is that the job of the police can be miscontrued as "arresting people". in the same way the job of a journalist can be miscontrued as "getting clicks"

overall I don't think we can pass an a priori moral judgement on that term, as essentially represent a statement that the default safety measures have failed.

(I want to reiterate that here I try not to intermingle my point with whether I believe or not that the current use is warranted, I am just trying to say that as a concept it needs to be part of an healthy democracy, the same as some distrust in electoral promises)

Re: Making Rust as Fast as Go

#158

Earlier quoted context omitted.

Fake News was a term invented around 2015 during the run-up to the 2016 election. It specifically referred to the phenomenon of literally fake news stories, such as rallies and completely false stories about politicians, being published by legitimate-sounding but nonexistent news organizations, using platforms like Facebook to disseminate themselves. Usually these were done from China and Russia.

And then trump redefined it to be about legitimate news sources exclusively. We’ve really been in upside down world for four years.

That's one of the reasons why I bring it up. If we don't stand against this dilution of a powerful term, it will be co-opted - which is exactly what people who want to destroy the trust of the press for their own personal and political ends want to do.

Re: Making Rust as Fast as Go

#159
post #154

Earlier quoted context omitted.

That's a fair criticism if clumsily put. For the record, I'm Canadian, British and Polish. I called out America as by far the biggest perpetrator at the moment. So to address the second half of your post, I have indeed heard of "other countries" (just ask USCIS) although being a US resident at the moment I want to speak to what I know, not for anyone else. Though if we're being super pedantic, there's only one human…

"That's a fair criticism if clumsily put" - I guess the original point was a shining example of elegance. USCIS - the same organ that asks women "have you ever been a prostitute" on citizenship tests? "Though if we're being super pedantic, there's only one human species on this planet -- species of course being defined as animals who can mate and produce viable offspring." You got me here ;)

[deleted]
Post reply on HN