Live data from Hacker News

Zlib-rs is faster than C

trifectatech.org

411–420 of 492 posts

Re: Zlib-rs is faster than C

#411

Earlier quoted context omitted.

Unsafe is a very distinct code smell. Like the hydrogen sulfide added to natural gas to allow folks to smell a gas leak. If you smell it when you're not working on the gas lines, that's a signal.

Someone mentioned to me that for something as simple as a Linked list you have to use unsafe in rust Update its how the std lib does it: https://doc.rust-lang.org/src/alloc/collections/linked_list....

Note that that is a doubly linked list, because it is a "soup of ownership" data structure. A singly linked list has clear ownership so it can be modelled in safe Rust.

On modern aschitectures you shouldn't use either unless you have an extremely niche use-case. They are not general use data structures anymore in a world where cache locality is a thing.

Re: Zlib-rs is faster than C

#412

Earlier quoted context omitted.

The encapsulation referred to here is that you can expose a safe API that is impossible to misuse in a way that leads to undefined behavior. That's the succinct way of putting it anyway. The `memchr` crate, for example, has an entirely safe API. Nobody needs to use `unsafe` to use any part of it. But its internals have `unsafe` littered everywhere. Could the crate have bugs that result in UB due to a particular use o…

"The encapsulation referred to here is that you can expose a safe API that is impossible to misuse in a way that leads to undefined behavior. That's the succinct way of putting it anyway." Well, no, actually. At least, not in an (IMHO) useful way. I can break your safe API by getting the constraints wrong on unsafe code inside that API. Also, unsafe usage elsewhere is not local. I can break your impossible to misuse…

> I can break your safe API by getting the constraints wrong on unsafe code inside that API.

This doesn't make any sense at all as a broader point. Of course you can break the safe API by introducing a bug inside the implementation! I honestly just cannot figure out how you have a misunderstanding of this magnitude, and I'm forced to conclude that we are mis-communicating at some level.

I did read the rest of your comment, and the most significant point I can take away from it is that you're making a claim about scale. I think the dissonance introduced with comments like the one above makes it very hard for me to trust your experience here and the conclusions you've drawn from it. But I will note that whether Rust's safety story scales is from my perspective a different thing entirely from the factual claim that Rust enables safe encapsulation of `unsafe` usage.

You may say that just because Rust enables safe encapsulation doesn't mean programmers using Rust actually follow through with that in practice. And yes, absolutely, it doesn't. You can't derive an is from an ought. But in my experience, it totally does. I do work on lots of "hobby" stuff in Rust (although I try to treat it professionally, I just mean that I am not directly paid for it beyond donations), but I am also paid to write Rust too. I do not have your experience with Rust at scale, so I cannot refute it. But you've said enough questionable things here that I can't trust it either.

Re: Zlib-rs is faster than C

#413

Earlier quoted context omitted.

I am hopping on Rust threads on HN very regularly and I have to tell you my anecdotal experience. Which is: people complaining about Rust zealots are much more than actual Rust zealots. Thinking of it, I haven't seen a proper Rust zealot on HN for at least a year at this point. So I don't know, maybe do less cheap digs. Tearing down straw men is pretty boring to watch.

Funny, because I could swear that for every comment that rises some criticism against Rust design/implementation/ergonomics/whatever, I find a dozen that "respectfully disagree", i.e. try very hard to deny validity of original claims. It is somewhat similar, actually, when someone states a negative opinion on Rust community and marketing around it. It is usually followed by those that say "you met wrong people". Of c…

Wait... zealotry is not "someone having a different opinion".

Literally that's what you're saying: they have a different opinion therefore they're zealots!

Unless people posting an opinion is itself zealotry... but in that case why are you complaining about the replies and not the comments they reply to?

Re: Zlib-rs is faster than C

#414
post #260

Earlier quoted context omitted.

Presumably a bounds check on the mask could be done or a safe variant exposed that does that trick under the hood. But yeah I don’t disagree that it’s “safe SIMD” is unlikely to scratch the itch for various applications but hopefully at least it’ll scratch a lot of them enough that the remaining unsafe is reduced.

No, a bounds check beats the purpose of simd in these cases

Not necessarily if you can hoist the bounds check outside of the loop somehow.

Re: Zlib-rs is faster than C

#415

Earlier quoted context omitted.

With unsafe you get exactly the same kind of semantics as C, if you don't uphold the invariant the unsafe functions expect, you end up with UB exactly like in C. If you want a clean crash instead on indeterministic behavior, you need to use assert like in C, but it won't save you from compiler optimization removing checks that are deemed useless (again, exactly like in C).

> With unsafe you get exactly the same kind of semantics as C, if you don't uphold the invariant the unsafe functions expect, you end up with UB exactly like in C. This is not exactly true. Even in production code, unsafe preconditions check if you violate these rules. Here: https://doc.rust-lang.org/core/macro.assert_unsafe_precondit... And here: https://google.github.io/comprehensive-rust/unsafe-rust/unsa...

Quoted from your link

> Safe Rust: memory safe, no undefined behavior possible. Unsafe Rust: can trigger undefined behavior if preconditions are violated.

So Unsafe Rust from a UB perspective is no different than C/C++. If preconditions are violated, UB can occur, affecting anywhere in the program. Its unclear how the compiler could check anything about preconditions in a block explicitly used to say that the developer is the one upholding the preconditions.

Re: Zlib-rs is faster than C

#416

Earlier quoted context omitted.

Funny, because I could swear that for every comment that rises some criticism against Rust design/implementation/ergonomics/whatever, I find a dozen that "respectfully disagree", i.e. try very hard to deny validity of original claims. It is somewhat similar, actually, when someone states a negative opinion on Rust community and marketing around it. It is usually followed by those that say "you met wrong people". Of c…

You can swear on anything, does not make it any more true. ¯\_(ツ)_/¯ All you do is defend very anecdotal evidence. Surely you can see this is not logically compelling.

He is replying to YOUR anecdotal experience though.

Re: Zlib-rs is faster than C

#417

Earlier quoted context omitted.

Funny, because I could swear that for every comment that rises some criticism against Rust design/implementation/ergonomics/whatever, I find a dozen that "respectfully disagree", i.e. try very hard to deny validity of original claims. It is somewhat similar, actually, when someone states a negative opinion on Rust community and marketing around it. It is usually followed by those that say "you met wrong people". Of c…

You can swear on anything, does not make it any more true. ¯\_(ツ)_/¯ All you do is defend very anecdotal evidence. Surely you can see this is not logically compelling.

In case you're ESL, you're downvoted because in this context "I swear" means "here comes some anecdotal evidence" and not "I promise this is true."

Re: Zlib-rs is faster than C

#418
post #371

Earlier quoted context omitted.

Fair enough. I suppose it is my most recent encounter. The result: I still don't like the rust community. You may have different opinions. I see no issue here.

I see the issue. Biased people like yourself don't belong in tech. For the record, I only picked Rust 5-ish years ago out of a 23 years of career. I know plenty of other languages. I was a skeptic at the start as well. Never generalized a pretty big group like you do though. You should be ashamed.

He should be ashamed because he does not like your community?

Re: Zlib-rs is faster than C

#419

Earlier quoted context omitted.

No, C lacks encapsulation of unsafe code. This is very important. Encapsulation is the only way to scale local reasoning into global correctness.

Eh. Good C programmers know what's safe and what's not. Often comments call out sketchy stuff. Just because it's not a language keyword, doesnt mean it's not called out. Bad C programmers though? Their stuff is more dangerous and they don't know when and don't call it out and should probably stick to Rust.

Dunno why this is being downvoted, obviously no true Scotsman would ever use memory after freeing it.

Re: Zlib-rs is faster than C

#420
post #382

Earlier quoted context omitted.

FTR I don't really have a problem with the rust language. I think there's some interesting ideas in there. I don't really like the syntax, but that's a minor nitpick. Not sure what to make of your other comments.

And I didn't say this was about Rust the language. I said many times it's not OK for you to generalize an entire community of hard-working people. It will never be OK. What is actually funny in our exchanges is that I don't even actively work with Rust anymore. I work with multiple languages, it included. I've met very smart, humble and fairly hardcore [Rust] devs from whom I learned a lot and got severely humbled as…

> generalize an entire community of hard-working people

By claiming they are hard-working, you are generalizing. It is usually only a couple or few that are actually hard-working people, but then again, I am generalizing because I do not know, I do not wish to actually claim to know.

Judging by your comments, e.g. "you should be ashamed" (for simply expressing his dislike of YOUR community), you sound exactly like a zealot.

Why do you feel the need to claim moral superiority and tell someone to be ashamed just for simply expressing their dislike of your community? And while we are at it, he probably dislikes the community because of people like you. We have gone full circle.

I am not even going to bother commenting on a lot of things you have said, but:

> My other comments are fairly trivial English. Surely you can very easily make something out of them.

Sounds condescending as well, but this is a minor nitpick. :)

Post reply on HN