• MalReynolds@slrpnk.net
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    4 months ago

    When you need speed in Python, after profiling, checking for errors, and making damn sure you actually need it, you code the slow bit in C and call it.

    When you need speed in C, after profiling, checking for errors, and making damn sure you actually need it, you code the slow bit in Assembly and call it.

    When you need speed in Assembly, after profiling, checking for errors, and making damn sure you actually need it, you’re screwed.

    Which is not to say faster Python is unwelcome, just that IMO its focus is frameworking, prototyping or bashing out quick and perhaps dirty things that work, and that’s a damn good thing.

    • Dave.@aussie.zone
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      4 months ago

      Generally I bash together the one-off programs in Python and if I discover that my “one off” program is actually being run 4 times a week, that’s when I look at switching to a compiled language.

      Case in point: I threw together a python program that followed a trajectory in a point cloud and erased a box around the trajectory. Found a python point cloud library, swore at my code (and the library code) for a few hours, tidied up a few point clouds with it, job done.

      And then other people in my company also needed to do the same thing and after a few months of occasional use, I rewrote it using C++ and Open3D. A few days of swearing this time (mainly because my C++ is a bit rusty, and Open3D’s C++ interface is a sparsely-documented back end to their main python front end).

      End result though is that point clouds that took 3 minutes to process before in python now take 10 seconds, and now there’s a visualisation widget that shows the effects of the processing so you don’t have to open the cloud in another viewer to see that it was ok.

      But anyway, like you said, python is good for prototyping, and when you hash out your approach and things are fairly nailed down and now you’d like some speed, jump to a compiled language and reap the benefits.

      • sugar_in_your_tea@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        ·
        4 months ago

        Python is also pretty good for production, provided you’re using libraries optimized in something faster. Is there a reason you didn’t use Open3D’s Python library? I’m guessing you’d get close to the same performance of the C++ code in a lot less time.

        That said, if you’re doing an animation in 3D, you should probably consider a game engine. Godot w/ GDScript would probably be good enough, though you’d spend a few days learning the engine (but the next project would be way faster).

        If you’re writing a performance-critical library, something compiled is often the better choice. If you’re just plugging libraries together, something like Python is probably a better use of your time since the vast majority of CPU time can generally be done in a library.

  • Diplomjodler@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    4 months ago

    In all the stuff I do in Python, runtime is not a consideration at all. Developer productivity is far more of a bottleneck. Having said that, I do of course see the value in these endeavours.

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      If everyone had a magic lamp that told them whether performance was going to be an issue when they started a project then maybe it wouldn’t matter. But in my experience people start Python projects with “performance doesn’t matter”, write 100k lines of code and then ask “ok it’s too slow now, what do we do”. To which the answer is “you fucked up, you shouldn’t have used Python”.

      • sugar_in_your_tea@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        4 months ago

        No, it’s usually “microservices” or “better queries” or something like that. Python performance shouldn’t be an issue in a well-architected application. Source: I work on a project with hundreds of thousands of lines of Python code.

        • FizzyOrange@programming.dev
          link
          fedilink
          arrow-up
          0
          ·
          4 months ago

          Well yeah if by “well architected” you mean “doesn’t use Python”.

          “microservices” or “better queries”

          Not everything is a web service. Most of the slow Python code I encounter is doing real work.

          • sugar_in_your_tea@sh.itjust.works
            link
            fedilink
            arrow-up
            0
            ·
            4 months ago

            We also do “real work,” and that uses libraries that use C(++) under the hood, like scipy, numpy, and tensorflow. We do simulations of seismic waves, particle physics simulations, etc. Most of our app is business logic in a webapp, but there’s heavy lifting as well. All of “our” code is Python. I even pitched using Rust for a project, but we were able to get the Python code “fast enough” with numba.

            We separate expensive logic that can take longer into background tasks from requests that need to finish quickly. We auto-scale horizontally as needed so everything remains responsive.

            That’s what I mean by “architected well,” everything stays responsive and we just increase our hosting costs instead of development costs. If we need to, we could always rewrite parts in a faster language, provided that costs less than the development costs. We really don’t spend much time at all optimizing python code, so we’re not at that point yet.

            That being said, I do appreciate faster-running code. I use Rust for most of my personal projects, but that’s because I don’t have to pay a team to maintain my projects.

            • FizzyOrange@programming.dev
              link
              fedilink
              arrow-up
              0
              ·
              4 months ago

              Matrix code is the very best case for offloading work from Python to something else though.

              Think about something like a build system (e.g. scons) or a package installer (pip). There is no part of them that you can point to and say “that’s the slow bit, write it in C” because the slowness is distributed through the entire thing.

              • sugar_in_your_tea@sh.itjust.works
                link
                fedilink
                arrow-up
                0
                ·
                4 months ago

                Both of those are largely bound by i/o, but with some processing in between, so the best way to speed things up is probably am async i/o loop that feeds a worker pool. In Python, you’d use processes, which can be expensive and a little complicated, but workable.

                And as you pointed out, scons and pip exist, and they’re fast enough. I actually use poetry, and it’s completely fine.

                You could go all out and build something like cargo, but it’s the architecture decisions that matter most in something i/o bound like that.

                • FizzyOrange@programming.dev
                  link
                  fedilink
                  arrow-up
                  0
                  ·
                  4 months ago

                  they’re fast enough

                  Strong disagree. I switched from pip to uv and it sped my install time up from 58 seconds to 7. Yeah really. If pip is i/o bound where is all that speed up coming from?