Live data from Hacker News

How much does Rust's bounds checking cost?

blog.readyset.io

1–10 of 195 posts

Re: How much does Rust's bounds checking cost?

#2
Similarly, you can turn off bounds-checking in Go like this:

  go build -gcflags=-B
and see if it helps. Generally the assembly looks better, but it doesn't really run faster on a modern chip.

Do your own test, and keep the results in mind next time somebody on Hacker News dismisses Go because of the "overwhelming cost of bounds checking".

Re: How much does Rust's bounds checking cost?

#4
A consistent 5 ms difference in micro-benchmarks is definitely not "measurement noise". Noise averages out way before accumulating to 5ms. There must be a reason and it mostly likely relates to the change. So you can confidently say that removing bounds checking (at least with how you did it) is a regression.

... that being said, I'd argue that the most beneficial memory-safety feature of Rust is about temporal things (i.e. prevents UAF etc) instead of spatial ones.

Re: How much does Rust's bounds checking cost?

#5
Can someone smarter than me enlighten me when you would consider disabling bounds checking for performance? In ways the compiler is not already doing so? The article starts with a bug that would have been prevented by bounds checking. It's like talking about how much faster a car would go if it didn't have to carry the extra weight of brakes.

Re: How much does Rust's bounds checking cost?

#6

I would expect an iterator into a slice to not incur any bounds checking, as the compiler can deduce the end pointer one time as start + size. So idiomatic looping should be maximally efficient you'd hope.

The compiler shouldn't have to deduce anything, an Iterator shouldn't have a bounds check to begin with. It ought to be using unsafe operations under the hood, because it can guarantee they will only be called with valid arguments.

Re: How much does Rust's bounds checking cost?

#7
post #4

A consistent 5 ms difference in micro-benchmarks is definitely not "measurement noise". Noise averages out way before accumulating to 5ms. There must be a reason and it mostly likely relates to the change. So you can confidently say that removing bounds checking (at least with how you did it) is a regression. ... that being said, I'd argue that the most beneficial memory-safety feature of Rust is about temporal thing…

A benchmarking harness without error bars?

Re: How much does Rust's bounds checking cost?

#9

Similarly, you can turn off bounds-checking in Go like this: go build -gcflags=-B and see if it helps. Generally the assembly looks better, but it doesn't really run faster on a modern chip. Do your own test, and keep the results in mind next time somebody on Hacker News dismisses Go because of the "overwhelming cost of bounds checking".

> next time somebody on Hacker News dismisses Go because of the "overwhelming cost of bounds checking".

That’s certainly one criticism I don’t remember ever seeing.

Re: How much does Rust's bounds checking cost?

#10

Can someone smarter than me enlighten me when you would consider disabling bounds checking for performance? In ways the compiler is not already doing so? The article starts with a bug that would have been prevented by bounds checking. It's like talking about how much faster a car would go if it didn't have to carry the extra weight of brakes.

> It's like talking about how much faster a car would go if it didn't have to carry the extra weight of brakes.

And there’s folks who do exactly that.

Post reply on HN