News for hackers. Stuff that matters.
Re:The world could run on older hardware if software optimiz... by Aurornis on Tuesday May 13, 2025 @03:32PM (#43976715)
> It doesn’t work like that. If an image processing algorithm takes 2 instructions per pixel, adding a check to every access could 3-4x the cost.

Your understanding of how bounds checking works in modern languages and compilers is not up to date. You're not going to find a situation where bounds checking causes an algorithm to take 3-4X longer.

A lot of people are surprised when the bounds checking in Rust is basically negligible, maybe 5% at most. In many cases if you use iterators you might not see a hit at all.

Then again, if you have an image processing algorithm that is literally reading every single pixel one-by-one to perform a 2-instruction operation and calculating bounds check on every access in the year 2025, you're doing a lot of things very wrong.

> This is why if you dictate bounds checking then the language becomes uncompetitive for certain tasks.

Do you have any examples at all? Or is this just speculation?

Re:The world could run on older hardware if software optimiz... by monkeyelite on Tuesday May 13, 2025 @03:36PM (#43976765)
> Your understanding of how bounds checking works in modern languages and compilers is not up to date.

One I am familiar with is Swift - which does exactly this because it’s a library feature of Array.

Which languages will always be able to determine through function calls, indirect addressing, etc whether it needs to bounds check or not?

And how will I know if it succeeded or whether something silently failed?

> if you have an image processing algorithm that is literally reading every single pixel one-by-one to perform a 2-instruction operation and calculating bounds check on every access in the year 2025, you're doing a lot of things very wrong

I agree. That’s what I said.

> Do you have any examples at all? Or is this just speculation?

Yes. Java and python are not competitive for graphics and audio processing.

Re:The world could run on older hardware if software optimiz... by MonkeyClub on Wednesday May 14, 2025 @10:17AM (#43984858)
> Java and python

Java and Python are not on the same body of water, let alone the same boat.

You can see some comparisons here:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re:The world could run on older hardware if software optimiz... by monkeyelite on Wednesday May 14, 2025 @06:01PM (#43989659)
Yes. And why is that?
Re:The world could run on older hardware if software optimiz... by Aurornis on Wednesday May 14, 2025 @06:35PM (#43989892)
Interpreted languages and garbage collection.

Bounds checking barely registers as a factor.

Re:The world could run on older hardware if software optimiz... by monkeyelite on Wednesday May 14, 2025 @09:40PM (#43991013)
You can write Java that uses arrays that are allocated once - will it have loops as fast as C? Why not?

And furthermore I don’t suspect you’re proposing we should be using C + bounds checking (that’s already a Gcc flag?). But rather bounds checking is one of many safety features.

The whole pitch of Java is exactly what OP said - let’s just pay 10-30% cost to get these nice portability and memory benefits over C++, and it didn’t work that way especially as memory speeds have diverged from CPU.

Re:The world could run on older hardware if software optimiz... by Aurornis on Wednesday May 14, 2025 @06:34PM (#43989886)
> Yes. Java and python are not competitive for graphics and audio processing.

Because Python is an interpreted language and Java has garbage collection, not because they have bounds checking.

Using a language like Rust the bounds checking overhead compared to C code is usually minimal, like 0-5%. The compiler can even optimize away many bounds checks (safely) if you structure your code properly, such as with iterators.

Here's an example article : https://shnatsel.medium.com/how-to-avoid-bounds-checks-in-ru...

Make sure you read the note about how the author was mistaken about the 15% speedup from bounds checking. The actual bounds check change was much less, like a couple percent. You can even structure your code so that the bounds check disappears altogether when the compiler can confirm safety at compile time.