• Ephera@lemmy.ml
    link
    fedilink
    arrow-up
    4
    ·
    4 months ago

    Honestly, it’s still ridiculous to me how slow Python, Java, JS, Ruby etc. continue to feel, even after decades of hardware optimizations. You’d think their slowness would stop being relevant at some point, because processors and whatnot have become magnitudes faster, but you can still feel it quite well, when something was implemented in one of those.

    • GissaMittJobb@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      4 months ago

      There are a few reasons for this, some of the most important being:

      • The languages were not designed with speed primarily in mind and as such made some design decisions that fundamentally cannot be optimized around
      • Authors of programs in these languages prioritize things other than performance when writing the programs.

      Speed is not just about processors becoming faster - this is a large part of why DSA is important to learn as a programmer.

    • Urist@lemmy.ml
      link
      fedilink
      English
      arrow-up
      2
      ·
      4 months ago

      Many of these have C-bindings for their libraries, which means that slowness is caused by bad code (such as making a for loop with a C-call for each iteration instead of once for the whole loop).

      I am no coder, but it is my experience that bad code can be slow regardless of language used.

      • Ephera@lemmy.ml
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        4 months ago

        Bad code can certainly be part of it. The average skill level of those coding C/C++/Rust tends to be higher. And modern programs typically use hundreds of libraries, so even if your own code is immaculate, not all of your dependencies will be.

        But there’s other reasons, too:

        • Python, Java etc. execute their compiler/interpreter while the program is running.
        • CLIs are magnitudes slower, because these languages require a runtime to be launched before executing the CLI logic.
        • GUIs and simulations stutter around, because these languages use garbage collection for memory management.
        • And then just death by a thousand paper cuts. For example, when iterating over text, you can’t tell it to just give you a view/pointer into the existing memory of the text. Instead, it copies each snippet of text you want to process into new memory.
          And when working with multiple threads in Java, it is considered best practice to always clone memory of basically anything you touch. Like, that’s good code and its performance will be mediocre. Also, you better don’t think about using multiple threads in Python+JS. For those two, even parallelism was an afterthought.

        Well, and then all of the above feeds back into all the libraries not being performant. There’s no chance to use the languages for performance-critical stuff, so no one bothers optimizing the libraries.

        • UnfortunateShort@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          4 months ago

          Java is still significantly faster and more efficient than Python tho - because it has ahead-of-time optimizations and is not executing plain text.

          • Ptsf@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            4 months ago

            Idk numpy go brrrrrrrrrr. I think it’s more just the right tool for the right job. Most languages have areas they excel at, and areas where they’re weaker, siloing yourself into one and thinking it’s faster for every implementation seems short sighted.

            • UnfortunateShort@lemmy.world
              link
              fedilink
              arrow-up
              2
              ·
              4 months ago

              At it’s heart, numpy is C tho. That’s exactly what I’m talking about. Python is amazing glue code. It makes this fast code more useful by wrapping it in simple® scripts and classes.

          • MeanEYE@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            4 months ago

            Faster, sure. Efficient, fuck no. With Java you have to run around and write ton of boiler plate code to do something simplest in nature.

            • UnfortunateShort@lemmy.world
              link
              fedilink
              arrow-up
              0
              ·
              edit-2
              4 months ago

              I’m mainly talking efficiency in terms of energy use. I won’t deny that some ugly decisions have been made with Java :D

              • MeanEYE@lemmy.world
                link
                fedilink
                arrow-up
                0
                arrow-down
                1
                ·
                4 months ago

                Energy use? That’s a pointless metric. If that is the goal then whole idea of desktop should be scraped. Waste of memory and hard drive space. Just imagine the amount of energy wasted on booting GUI.

                  • MeanEYE@lemmy.world
                    link
                    fedilink
                    arrow-up
                    0
                    arrow-down
                    1
                    ·
                    4 months ago

                    If you want to talk about climate change then electronics is the wrong place to point the finger at. For start look at cement manufacturing. It requires huge amounts of energy to produce even though we have eco-friendly variants ready to go. And cement production amounts to 8% of all greenhouse gasses released annually.

                    Hell, just ban private jets and you’ve offset all of the bad things datacenters ever made. Elon had 10 minute flight to avoid traffic which consumed around 300l of fuel. Royal family makes so many flights a year that you could go into the wild and eat bark until the rest of your life and you wouldn’t be able to offset their footprint in thousands of lives.

                    Bill Gates himself talks a lot about reducing carbon footprint we make and yet he refuses to sell his collection of airplanes. He has A COLLECTION of them.

                    Using higher level language that requires more operations than assembler is not a thing to worry about when talking about climate change. Especially without taking into account how much pollution have those managed to reduce by smartly controlling irrigation and other processes.

        • TimeSquirrel@kbin.melroy.org
          link
          fedilink
          arrow-up
          2
          ·
          4 months ago

          For example, when iterating over text, you can’t tell it to just give you a view/pointer into the existing memory of the text. Instead, it copies each snippet of text you want to process into new memory.

          As someone used to embedded programming, this sounds horrific.

          • Ephera@lemmy.ml
            link
            fedilink
            arrow-up
            1
            ·
            4 months ago

            Yep. I used to code a lot in JVM languages, then started learning Rust. My initial reaction was “Why the hell does Rust have two string types?”.
            Then I learned that it’s for representing actual memory vs. view and what that meant. Since then I’m thinking “Why the hell do JVM languages not have two string types?”.

            • calcopiritus@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              4 months ago

              I’m not a java programmer, but I think the equivalent to str would be char[]. However the ergonomics of rust for str isn’t there for char[], so java devs probably use String everywhere.

      • aluminium@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        4 months ago

        At least with Java, its the over(ab)use of Reflections and stuff like dependency injection that slows things down to a crawl.

    • Possibly linux@lemmy.zip
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      4 months ago

      “Slow”

      They aren’t as fast as a native language but they aren’t all that slow if you aren’t trying to use them for performance sensitive applications. Modern machines run all those very quickly as CPUs are crazy fast.

      Also it seems weird to put Java/OpenJDK in the list as it is in its own category from my experience

      • Ephera@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        4 months ago

        Java is certainly the fastest of the bunch, but I still find it rather noticeable how long the startup of applications takes and how it always feels a bit laggy when used for graphical stuff.

        Certainly possible to ignore that on a rational level, but that’s why I’m talking about how it feels.
        I’m guessing, this has to do with just the basic UX principle of giving the user feedback. If I click a button, I want feedback that my click was accepted and when the triggered action completed. The sooner those happen, the more confident I feel about my input and the better everything feels.

        • Possibly linux@lemmy.zip
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 months ago

          I’ve never experienced that. Also Android is OpenJDK based and the applications in Android work well and the system is well optimized

    • MeanEYE@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      4 months ago

      That’s because it’s not relevant. Speed can be compensated for either by caching or outsourcing your load, if there’s such a huge need to process large amount of data quickly. In day to day work I can’t say I have ever ran into issues because code was executing slow. Normal operation Python is more than capable of keeping up.

      On the other side of the coin you have memory management, buff and stack overflows and general issues almost exclusive to C, which is something you don’t have to worry about as much with higher level languages. Development with Python is simply faster and safer. We as developers have different tools, and we should use them for their appropriate purpose. You can drive nails with a rock as well, but you generally don’t see carpenters doing this all day.

      • AlotOfReading@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        4 months ago

        You can sometimes deal with performance issues by caching, if you want to trade one hard problem for another (cache invalidation). There’s plenty of cases where that’s not a solution though. I recently had a 1ns time budget on a change. That kind of optimization is fun/impossible to do in Python and straightforward to accomplish Rust or C/C++ once you’ve set up your measurements.

        • MeanEYE@lemmy.world
          link
          fedilink
          arrow-up
          0
          arrow-down
          1
          ·
          4 months ago

          Which is exactly what I said. Most of the times you can work around it. Sure cache invalidation can be hard, but doesn’t have to be. If you need performance use more performant language. Right tool for the job.