Skip to content

Why This Python Performance Trick Doesn’t Matter Anymore

Technology
4 4 0
  • 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.

  • Uber, Lyft oppose some bills that aim to prevent assaults during rides

    Technology technology
    12
    94 Stimmen
    12 Beiträge
    32 Aufrufe
    F
    California is not Colorado nor is it federal No shit, did you even read my comment? Regulations already exist in every state that ride share companies operate in, including any state where taxis operate. People are already not supposed to sexually assault their passengers. Will adding another regulation saying they shouldn’t do that, even when one already exists, suddenly stop it from happening? No. Have you even looked at the regulations in Colorado for ride share drivers and companies? I’m guessing not. Here are the ones that were made in 2014: https://law.justia.com/codes/colorado/2021/title-40/article-10-1/part-6/section-40-10-1-605/#%3A~%3Atext=§+40-10.1-605.+Operational+Requirements+A+driver+shall+not%2Ca+ride%2C+otherwise+known+as+a+“street+hail”. Here’s just one little but relevant section: Before a person is permitted to act as a driver through use of a transportation network company's digital network, the person shall: Obtain a criminal history record check pursuant to the procedures set forth in section 40-10.1-110 as supplemented by the commission's rules promulgated under section 40-10.1-110 or through a privately administered national criminal history record check, including the national sex offender database; and If a privately administered national criminal history record check is used, provide a copy of the criminal history record check to the transportation network company. A driver shall obtain a criminal history record check in accordance with subparagraph (I) of paragraph (a) of this subsection (3) every five years while serving as a driver. A person who has been convicted of or pled guilty or nolo contendere to driving under the influence of drugs or alcohol in the previous seven years before applying to become a driver shall not serve as a driver. If the criminal history record check reveals that the person has ever been convicted of or pled guilty or nolo contendere to any of the following felony offenses, the person shall not serve as a driver: (c) (I) A person who has been convicted of or pled guilty or nolo contendere to driving under the influence of drugs or alcohol in the previous seven years before applying to become a driver shall not serve as a driver. If the criminal history record check reveals that the person has ever been convicted of or pled guilty or nolo contendere to any of the following felony offenses, the person shall not serve as a driver: An offense involving fraud, as described in article 5 of title 18, C.R.S.; An offense involving unlawful sexual behavior, as defined in section 16-22-102 (9), C.R.S.; An offense against property, as described in article 4 of title 18, C.R.S.; or A crime of violence, as described in section 18-1.3-406, C.R.S. A person who has been convicted of a comparable offense to the offenses listed in subparagraph (I) of this paragraph (c) in another state or in the United States shall not serve as a driver. A transportation network company or a third party shall retain true and accurate results of the criminal history record check for each driver that provides services for the transportation network company for at least five years after the criminal history record check was conducted. A person who has, within the immediately preceding five years, been convicted of or pled guilty or nolo contendere to a felony shall not serve as a driver. Before permitting an individual to act as a driver on its digital network, a transportation network company shall obtain and review a driving history research report for the individual. An individual with the following moving violations shall not serve as a driver: More than three moving violations in the three-year period preceding the individual's application to serve as a driver; or A major moving violation in the three-year period preceding the individual's application to serve as a driver, whether committed in this state, another state, or the United States, including vehicular eluding, as described in section 18-9-116.5, C.R.S., reckless driving, as described in section 42-4-1401, C.R.S., and driving under restraint, as described in section 42-2-138, C.R.S. A transportation network company or a third party shall retain true and accurate results of the driving history research report for each driver that provides services for the transportation network company for at least three years. So all sorts of criminal history, driving record, etc checks have been required since 2014. Colorado were actually the first state in the USA to implement rules like this for ride share companies lol.
  • 272 Stimmen
    77 Beiträge
    17 Aufrufe
    S
    I don't believe the idea of aggregating information is bad, moreso the ability to properly vet your sources yourself. I don't know what sources an AI chatbot could be pulling from. It could be a lot of sources, or it could be one source. Does it know which sources are reliable? Not really. AI has been infamous for hallucinating even with simple prompts. Being able to independently check where your info comes from is an important part of stopping the spread of misinfo. AI can't do that, and, in it's current state, I wouldn't want it to try. Convenience is a rat race of cutting corners. What is convenient isn't always what is best in the long run.
  • 29% of adults couldn't go hour without internet - survey

    Technology technology
    18
    1
    68 Stimmen
    18 Beiträge
    58 Aufrufe
    saltsong@startrek.websiteS
    Because we don't want them doing surge pricing.
  • 121 Stimmen
    21 Beiträge
    77 Aufrufe
    T
    I thought Trump and Elon had a major falling out? Actually now that I think of it, news about that fizzled out very quickly. Did they silently kiss and make up behind closed doors or something?
  • Amazon Doubles Prime Video Ads Per Hour

    Technology technology
    126
    1
    624 Stimmen
    126 Beiträge
    150 Aufrufe
    V
    Me too, except I didn't get the email saying my pro vpn was about to expire, which might be my fault ofc. Gotta check the oarameters It's really good IMO and I'd recommend it fullheartedly, Switzerland has some of the best laws out there too concerning privacy too.
  • Apple acquires RAC7, its first-ever video game studio

    Technology technology
    16
    1
    67 Stimmen
    16 Beiträge
    48 Aufrufe
    E
    I'm not questioning whether or not the game is good, just wondering why Apple would want to limit their customer base so much.
  • 358 Stimmen
    113 Beiträge
    126 Aufrufe
    S
    The problem is the cost of each. Right now material is dirt cheap and energy prices are going up. And we are not good at long term planning.
  • 236 Stimmen
    80 Beiträge
    80 Aufrufe
    R
    Yeah, but that's a secondary attribute. The new ones are stupid front and center.