Skip to content

Why This Python Performance Trick Doesn’t Matter Anymore

Technology
4 4 56
  • This post did not contain any content.
  • This post did not contain any content.

    TLDR: 3.11 is twice as fast as 3.10 at doing global name lookups, so an old speedup hack of aliasing a global function locally isn't needed.

    For example, when calling len() in a loop, going l=len, and calling l() in the loop was faster in 3.10. In 3.11, moreso in 3.13, it's almost a wash.

    However, the author says this:

    Accessing functions through a module [e.g. math.sin()] or a deep attribute chain can still carry overhead. Creating a local alias or using "from module import name" continues to be effective in those situations.

    But when I look at the numbers, I would say 3.13 is pretty close to making it an unnecessary optimization in general. A little subjective on how you interpret the numbers.

    Great info, but this was like trying to use a recipe and reading the author's life story to get there.

  • TLDR: 3.11 is twice as fast as 3.10 at doing global name lookups, so an old speedup hack of aliasing a global function locally isn't needed.

    For example, when calling len() in a loop, going l=len, and calling l() in the loop was faster in 3.10. In 3.11, moreso in 3.13, it's almost a wash.

    However, the author says this:

    Accessing functions through a module [e.g. math.sin()] or a deep attribute chain can still carry overhead. Creating a local alias or using "from module import name" continues to be effective in those situations.

    But when I look at the numbers, I would say 3.13 is pretty close to making it an unnecessary optimization in general. A little subjective on how you interpret the numbers.

    Great info, but this was like trying to use a recipe and reading the author's life story to get there.

    Thanks for the summary!

    Yeah, in Python each . is a dictionary lookup. The cost of having a dynamic language where the compiler can do pretty much no optimizations (and yes, Python does have a compiler).

    In static languages these lookups can be collapsed to a single pointer address by the compiler.

  • TLDR: 3.11 is twice as fast as 3.10 at doing global name lookups, so an old speedup hack of aliasing a global function locally isn't needed.

    For example, when calling len() in a loop, going l=len, and calling l() in the loop was faster in 3.10. In 3.11, moreso in 3.13, it's almost a wash.

    However, the author says this:

    Accessing functions through a module [e.g. math.sin()] or a deep attribute chain can still carry overhead. Creating a local alias or using "from module import name" continues to be effective in those situations.

    But when I look at the numbers, I would say 3.13 is pretty close to making it an unnecessary optimization in general. A little subjective on how you interpret the numbers.

    Great info, but this was like trying to use a recipe and reading the author's life story to get there.

    I'm surprised about the module lookup thing, since I assumed it was just syntax sugar to do from ... import .... We do the from syntax almost everywhere, but I've been replacing huge import blocks with a module import (e.g. constants) just to clean up the imports a bit and git conflicts.

    Looks like I'll need to keep this in mind until we upgrade to 3.13.

  • Big O vs Hardware: Better Complexity ≠ Better Performance

    Technology technology
    4
    1
    48 Stimmen
    4 Beiträge
    13 Aufrufe
    F
    TL;DR: Big-O notation describes asymptotic behavior
  • Substack promoted a Nazi blog again

    Technology technology
    54
    1
    500 Stimmen
    54 Beiträge
    512 Aufrufe
    infinitehench@lemmy.worldI
    Unfortunately popular newsletter service that also puts your issues online to look like a blog. Has a lot of startup capital behind it so they've been paying some of their largest writers on top of subscriber revenue. Big "marketplace of ideas" idiots who have allowed a lot of white supremacist and - as this and other situations exemplify - straight up Nazi content.
  • Getting Started with Ebitengine (Go game engine)

    Technology technology
    1
    0 Stimmen
    1 Beiträge
    6 Aufrufe
    Niemand hat geantwortet
  • Google’s electricity demand is skyrocketing

    Technology technology
    11
    1
    190 Stimmen
    11 Beiträge
    113 Aufrufe
    W
    What's dystopian is that a company like google will fight tooth and nail to remain the sole owner and rights holder to such a tech. A technology that should be made accessible outside the confines of capitalist motives. Such technologies have the potential to lift entire populations out of poverty. Not to mention that they could mitigate global warming considerably. It is simply not in the interest of humanity to allow one or more companies to hold a monopoly over such technology
  • Rediscovering Human Purpose in the Age of AI

    Technology technology
    2
    1
    3 Stimmen
    2 Beiträge
    30 Aufrufe
    capuccino@lemmy.worldC
    well, it seems that the rich will stay rich, no matter what. It's incredible that people see AI as a religion now
  • Study finds persistent spike in hate speech on X

    Technology technology
    43
    1
    348 Stimmen
    43 Beiträge
    627 Aufrufe
    E
    You are a zionist so it's funny that you say that
  • Is Matrix cooked?

    Technology technology
    54
    101 Stimmen
    54 Beiträge
    484 Aufrufe
    W
    Didn't know it only applied to UWP apps on Windows. That does seem like a pretty big problem then. it is mostly for compatibility reasons. no win32 programs are equipped to handle such granular permissions and sandboxing, they are all made with the assumption that they have access to whatever they need (other than other users' resources and things that require elevation). if Microsoft would have made that limitation to every kind of software, that Windows version would have probably been a failure in popularity because lots of software would have broken. I think S editions of windows is how they tried to go in that direction, with a more drastic way of simply just dropping support for 3rd party win32 programs. I don't still have a Mac readily available to test with but afaik it is any application that uses Apple's packaging format. ok, so if you run linux or windows utils in a compatibility layer, they still have less of a limited access? by which I mean graphical utilities. just tried with firefox, for macos it wanted to give me an .iso file (???) if so, it seems apple is doing roughly the same as microsoft with uwp and the appx format, and linux with flatpak: it's a choice for the user
  • 1 Stimmen
    1 Beiträge
    19 Aufrufe
    Niemand hat geantwortet