GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Extend and improve `LOAD_COMMON_CONSTANT` · Issue #148871 · python/cpython

Extend and improve LOAD_COMMON_CONSTANT #148871

New issue
Copy link
New issue
Copy link
Open
Open
Extend and improve LOAD_COMMON_CONSTANT#148871
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@markshannon
markshannon
opened on Apr 22, 2026
Issue body actions

Currently LOAD_COMMON_CONSTANT only loads 7 not-so-common constants and does so fairly inefficiently.

It could be improved in two ways:

  • Add some more constants, especially None, but also "", True, False and -1
  • Make the constants that it does load both statically allocated and immortal to avoid the pointer chasing and incref operation. Only any and all would need changing.

After some consideration, I think it best to leave the common constants table per interpreter, and not statically allocate them.

  • The changes to any and all may be breaking.
  • We also need to handle AssertionError and NotImplementedError will be tricky to make static

They should all be immortal though, and stored as _PyStackRefs not PyObject *s.

Linked PRs

  • gh-148871: extend and improve LOAD_COMMON_CONSTANT #148971
  • gh-148871: make LOAD_COMMON_CONSTANT use immortal stackref borrows #149625
  • gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT #149688

Activity

  1. markshannon
    added
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Apr 22, 2026
  2. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Apr 22, 2026
  3. NekoAsakura
    added 5 commits that reference this issue on Apr 26, 2026

    Merge branch 'main' into pythongh-148871/load-common-constant

    22595cd

    Merge branch 'main' into pythongh-148871/load-common-constant

    ebd1c28

    Merge branch 'main' into pythongh-148871/load-common-constant

    558a5ac

    Merge branch 'main' into pythongh-148871/load-common-constant

    b017ae9

    Merge branch 'main' into pythongh-148871/load-common-constant

    cbd17a2
  4. markshannon
    added a commit that references this issue on May 2, 2026

    gh-148871: extend and improve `LOAD_COMMON_CONSTANT` (GH-148971)

    7c9ad27
  5. markshannon commented on May 2, 2026

    @markshannon
    markshannon
    on May 2, 2026
    MemberAuthor
    More actions

    Now #148971 is merged, we need to make LOAD_COMMON_CONSTANT fast.

    Instead of storing an array of PyObject *s the array should contain _PyStackRefs and all objects should be made immortal.

    So, instead of

    interp->common_consts[CONSTANT_BUILTIN_ALL] = all;
    

    we should have

    _Py_SetImmortal(all);
    interp->common_consts[CONSTANT_BUILTIN_ALL] = _PyStackRef_FromPyObjectBorrow(all);
    

    most objects in the common constants set are already immortal.

    Then the code for LOAD_COMMON_CONSTANT becomes

            value = tstate->interp->common_consts[oparg];
    

    Without any need to handle refcounts.

  6. eendebakpt
    added a commit that references this issue on May 11, 2026

    Add NEWS entry for pythongh-148871

    56d633a
  7. NekoAsakura
    added a commit that references this issue on May 21, 2026

    Merge branch 'main' into pythongh-148871-immortal-stackref

    d81f9b6
  8. markshannon
    added a commit that references this issue on May 21, 2026

    gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT (GH-149688)

    f2fa291
  9. NekoAsakura
    added 2 commits that reference this issue on May 21, 2026

    Merge branch 'main' into pythongh-148871-immortal-stackref

    0cf0de2

    Merge branch 'main' into pythongh-148871-immortal-stackref

    9bbbb46
  10. markshannon
    added a commit that references this issue on May 28, 2026

    gh-148871: make `LOAD_COMMON_CONSTANT` use immortal stackref borrows (G…

    39bd44f
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.