• csm10495@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    20
    ·
    4 months ago

    It’s exciting, but man there are lots of assumptions in native python built around the gil.

    I’ve seen lists, etc. modified by threads assuming the gil locks for them. Testing this e2e for any production deployment can be a bit of a nightmare.

  • BB_C@programming.dev
    link
    fedilink
    arrow-up
    16
    arrow-down
    1
    ·
    4 months ago

    While pure Python code should work unchanged, code written in other languages or using the CPython C API may not. The GIL was implicitly protecting a lot of thread-unsafe C, C++, Cython, Fortran, etc. code - and now it no longer does. Which may lead to all sorts of fun outcomes (crashes, intermittent incorrect behavior, etc.).

    :tabclose

    • vrighter@discuss.tchncs.de
      link
      fedilink
      arrow-up
      3
      ·
      4 months ago

      those libraries include pretty much almost all popular libraries. It’s just impossible to write performant code in python.

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

    I have a project ready to try this out. It’s a software simulator, and each run (typically 10-10,000 iterations) can be done independently, with the results aggregated and shown at the end. It’s also instrumented to show CPU and memory usage, and on MacOS, you can watch how busy each core gets (hint: PEGGED in multicore mode).

    Can run it single-threaded, then with multiprocessing, then with multi-core and time each one. Pretty happy with multicore, but as soon as the no-GIL/subinterpreter version is stable, will try it out and see if it makes any difference. Under the hood it uses numpy and scipy, so will have to wait for them.

    Edit: on my todo list is to try it all out in Mojo. They make pretty big performance gain claims.

  • roadrunner_ex@lemmy.ca
    link
    fedilink
    English
    arrow-up
    0
    ·
    4 months ago

    I’m curious to see how this whole thing shakes out. Like, will removing the GIL be an uphill battle that everyone regrets even suggesting?Will it be so easy, we wonder why we didn’t do it years ago? Or, most likely, somewhere in the middle?

      • roadrunner_ex@lemmy.ca
        link
        fedilink
        English
        arrow-up
        0
        ·
        4 months ago

        Yes, testing infrastructure is being put in place and some low-hanging fruit bugs have already been squashed. This bodes well, but it’s still early days, and I imagine not a lot of GIL-less production deployments are out there yet - where the real showstoppers will potentially live.

        I’m tenatively optimistic, but threading bugs are sometimes hard to catch

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

          threading bugs are sometimes hard to catch

          Putting it mildly! Threading bugs are probably the worst class of bugs to debug

          Definitely debatable if this is worth the risk of impossible bugs. Python is very slow, and multi threading isn’t going to change that. 4x extremely slow is still extremely slow. If you care remotely about performance you need to use a different language anyway.

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

            Python can be extremely slow, it doesn’t have to be. I recently re-wrote a stats program at work and got a ~500x speedup over the original python and a 10x speed up over the c++ rewrite of that. If you know how python works and avoid the performance foot-guns like nested loops you can often (though not always) get good performance.

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

              Unless the C++ code was doing something wrong there’s literally no way you can write pure Python that’s 10x faster than it. Something else is going on there. Maybe the c++ code was accidentally O(N^2) or something.

              In general Python will be 10-200 times slower than C++. 50x slower is typical.

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

                Nope, if you’re working on large arrays of data you can get significant speed ups using well optimised BLAS functions that are vectorised (numpy) which beats out simply written c++ operating on each array element in turn. There’s also Numba which uses LLVM to jit compile a subset of python to get compiled performance, though I didnt go to that in this case.

                You could link the BLAS libraries to c++ but its significantly more work than just importing numpy from python.

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

                  numpy

                  Numpy is written in C.

                  Numba

                  Numba is interesting… But a) it can already do multithreading so this change makes little difference, and b) it’s still not going to be as fast as C++ (obviously we don’t count the GPU backend).