this post was submitted on 24 Apr 2025
12 points (100.0% liked)

Programming

19728 readers
81 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS
 

Undefined Behavior in C and C+- is often exploited by compilers for optimization. Therefore, it is frequently believed that permitting Undefined Behaviour makes such programs faster, even if the architectures of today's hardware are wildly different from the tiny and bare-bones CPUs these languages were once developed for, fifty years ago.

This study examines whether this is the case, by disabling many of such optimizations in clang and running a wide range of "optimized" and "unoptimized" benchmarks on Intel, AMD, and ARM architectures.

The general result is that while there are differences, the benchmarks do not run significantly faster with "optimizations". A slowdown was observed on ARM - only if no link time optimization (LTO) was used. Averaged ifferences even with all "ub-based optimizations" enabled or disabled were typically below 2%, which is at the noise threshold.

There were also many cases where "UB-optimizations" made programs perform worse.

There were exceptions found to this general summary, and the causes for this were tracked down and explained.

Considering all that, the performance impact of permitting UB appears to be... a myth?

you are viewing a single comment's thread
view the rest of the comments
[–] HaraldvonBlauzahn@feddit.org 2 points 17 hours ago

Great article, a pleasure to read and a fantastic work of really good science and critical thinking.