• ChickenLadyLovesLife@lemmy.world
    link
    fedilink
    English
    arrow-up
    16
    ·
    5 months ago

    It’s kind of funny how eagerly we programmers criticize “premature optimization”, when often optimization is not premature at all but truly necessary. A related problem is that programmers often have top-of-the-line gear, so code that works acceptably well on their equipment is hideously slow when running on normal people’s machines. When I was managing my team, I would encourage people to develop on out-of-date devices (or at least test their code out on them once in a while).

    • AnyOldName3@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      5 months ago

      Premature optimisation often makes things slower rather than faster. E.g. if something’s written to have the theoretical optimal Big O complexity class, that might only break even around a million elements, and be significantly slower for a hundred elements where everything fits in L1 and the simplest implemention possible is fine. If you don’t know the kind of situations the implementation will be used in yet, you can’t know whether the optimisation is really an optimisation. If it’s only used a few times on a few elements, then it doesn’t matter either way, but if it’s used loads but only ever on a small dataset, it can make things much worse.

      Also, it’s common that the things that end up being slow in software are things the developer didn’t expect to be slow (otherwise they’d have been careful to avoid them). Premature optimisation will only ever affect the things a developer expects to be slow.

    • AeonFelis@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      5 months ago

      It’s kind of funny how eagerly we programmers criticize “premature optimization”, when often optimization is not premature at all but truly necessary.

      I will forever be salty about that one time I blamed of premature optimization for pushing to optimize a code that was allocating memory faster than the GC could free it, which was causing one of the production servers to keep getting OOM crashes.

      If urgent emails from one of the big clients who put the entire company into emergency mode during a holiday is still considered “premature”, then no optimization is ever going to be mature.