this post was submitted on 10 Jul 2023
70 points (97.3% liked)

Programming

17319 readers
150 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 1 year ago
MODERATORS
 

I've started noticing articles and YouTube videos touting the benefits of branchless programming, making it sound like this is a hot new technique (or maybe a hot old technique) that everyone should be using. But it seems like it's only really applicable to data processing applications (as opposed to general programming) and there are very few times in my career where I've needed to use, much less optimize, data processing code. And when I do, I use someone else's library.

How often does branchless programming actually matter in the day to day life of an average developer?

you are viewing a single comment's thread
view the rest of the comments
[–] Spzi@lemm.ee 16 points 1 year ago (2 children)

The better of those articles and videos also emphasize you should test and measure, before and after you "improved" your code.

I'm afraid there is no standard, average solution. You trying to optimize your code might very well cause it to run slower.

So unless you have good reasons (good as in 'proof') to do otherwise, I'd recommend to aim for readable, maintainable code. Which is often not optimized code.

[–] firelizzard@programming.dev 5 points 1 year ago (2 children)

One of the reasons I love Go is that it makes it very easy to collect profiles and locate hot spots.

The part that seems weird to me is that these articles are presented as if it's a tool that all developers should have in their tool belt, but in 10 years of professional development I have never been in a situation where that kind of optimization would be applicable. Most optimizations I've done come down to: I wrote it quickly and 'lazy' the first time, but it turned out to be a hot spot, so now I need to put in the time to write it better. And most of the remaining cases are solved by avoiding doing work more than once. I can't recall a single time when a micro-optimization would have helped, except in college when I was working with microcontrollers.

[–] otl@lemmy.sdf.org 4 points 1 year ago

Given the variety of software in existence I think it’s hard to say that something is so universally essential. Do people writing Wordpress plugins need to know about branch prediction? What about people maintaining that old .NET 3.5 application keeping the business running? VisualBasic macros?

I agree it’s weird. Probably more about getting clicks/views.

[–] tvbusy@lemmy.dbzer0.com 2 points 1 year ago

Please please please, God, Allah, Buddha, any god or non god out there, please don't let any engineer bringing up branchless programming for a AWS lambda function in our one-function-per-micro-service f*ckitechture.

[–] philm@programming.dev 2 points 1 year ago

Exactly, this sounds like a good way to optimize prematurely...