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?

  • Spzi@lemm.ee
    link
    fedilink
    English
    arrow-up
    17
    ·
    1 year ago

    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.

    • EthanOP
      link
      fedilink
      English
      arrow-up
      5
      ·
      1 year ago

      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.

      • Oliver Lowe@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        5
        ·
        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
        link
        fedilink
        English
        arrow-up
        3
        ·
        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
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

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