Skip to content

Globals / builtins cache #54610

Description

@pitrou
BPO 10401
Nosy @birkenfeld, @rhettinger, @abalkin, @pitrou, @vstinner, @ericvsmith, @benjaminp, @alex, @methane, @davidmalcolm
Files
  • globcache5.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-12-25.13:42:25.478>
    created_at = <Date 2010-11-12.21:24:29.912>
    labels = ['interpreter-core', '3.7', 'performance']
    title = 'Globals / builtins cache'
    updated_at = <Date 2019-12-25.13:42:25.477>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2019-12-25.13:42:25.477>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-12-25.13:42:25.478>
    closer = 'methane'
    components = ['Interpreter Core']
    creation = <Date 2010-11-12.21:24:29.912>
    creator = 'pitrou'
    dependencies = []
    files = ['19590']
    hgrepos = []
    issue_num = 10401
    keywords = ['patch']
    message_count = 6.0
    messages = ['121081', '121105', '121147', '121150', '282608', '358864']
    nosy_count = 15.0
    nosy_names = ['jhylton', 'nnorwitz', 'georg.brandl', 'rhettinger', 'belopolsky', 'sdahlbac', 'titanstar', 'pitrou', 'vstinner', 'eric.smith', 'thomaslee', 'benjamin.peterson', 'alex', 'methane', 'dmalcolm']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue10401'
    versions = ['Python 3.7']

    Activity

    1. pitrou commented on Nov 12, 2010

      @pitrou
      MemberAuthor

      Here is the Nth patch for a globals/builtins cache. As other caches at the same kind, it shows very small to no gain on non-micro benchmarks, showing that contrary to popular belief, globals/builtins lookup are not a major roadblock in today's Python performance.

      However, this patch could be useful in combination with other optimizations such as bpo-10399. Indeed, using the globals/builtins version id, it is easy and very cheap to detect whether the function pointed to by a global name has changed or not.

      As for micro-benchmarks, they show that there is indeed a good improvement on builtins lookups:

      $ ./python -m timeit "x=len;x=len;x=len;x=len;x=len;x=len;x=len;x=len;x=len;x=len;"
      -> without patch:
      1000000 loops, best of 3: 0.282 usec per loop
      -> with patch:
      10000000 loops, best of 3: 0.183 usec per loop
    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      performancePerformance or resource usage
      on Nov 12, 2010
    3. smontanaro commented on Nov 13, 2010

      @smontanaro
      Contributor

      Might such a cache lay the groundwork for more aggressive optimizations
      by JITs like Unladen Swallow?

    4. brettcannon commented on Nov 13, 2010

      @brettcannon
      Member

      Unladen actually has something like this in place for performance optimizations. Not sure how Antoine's approach differs, though.

    5. pitrou commented on Nov 13, 2010

      @pitrou
      MemberAuthor

      There aren't many possible approaches. The more complex variants of globals caches try to also speedup writes, which is IMO a waste of time since rebinding globals is not a good coding practice, and especially not in the middle of time-critical loops.

      (by the way, the patch only addresses normal functions, but generators would easily benefit from a similar treatment)

      And Skip is right that this would be most useful when paired with a JIT (allowing for aggressive specialization, and possibly inlining).

    6. methane commented on Dec 7, 2016

      @methane
      Member

      dict has ma_version for now.

      @Haypo, how do you think about this patch?
      Would you reimplement global cache? Or may I update this patch?

    7. methane commented on Dec 25, 2019

      @methane
      Member

      This is implemented in bpo-26219.

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions