FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT by eendebakpt · Pull Request #149688 · python/cpython · GitHub

/ cpython Public

gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT - #149688

Merged
markshannon merged 3 commits into
python:mainfrom
eendebakpt:load-common-const-empty-tuple
May 21, 2026
Merged

gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT#149688
markshannon merged 3 commits into
python:mainfrom
eendebakpt:load-common-const-empty-tuple

Conversation

eendebakpt commented May 11, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Add () as a new value for LOAD_COMMON_CONSTANT, following the existing pattern used for "" (CONSTANT_EMPTY_STR). The compiler now folds LOAD_CONST () into LOAD_COMMON_CONSTANT 12, dropping the entry from co_consts.

() is the most common constant left in co_consts after the existing LOAD_COMMON_CONSTANT rewrites. Frequencies in co_consts (top-level entries, recursing into nested code objects):

Constant stdlib (613,524 entries) pyperformance (9,550 entries) Immortal singleton?
() 14,270 (2.33%) 112 (1.17%) yes (Py_CONSTANT_EMPTY_TUPLE)
b"" 1,012 (0.16%) 4 (0.04%) yes (Py_CONSTANT_EMPTY_BYTES)
1.0 516 (0.08%) 14 (0.15%) no (would need new immortal float)
0.0 457 (0.07%) 13 (0.14%) no (would need new immortal float; care re: -0.0)
... 139 (0.02%) 1 (0.01%) yes (_Py_EllipsisObject)

Common sources of (): __slots__ = (), empty default-args tuples passed to MAKE_FUNCTION, __reduce__ returning (), etc.

b"" and ... are already immortal singletons, but less frequent. For reviewers: should we add these as well?

python-cla-bot Bot commented May 11, 2026
edited
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
eendebakpt force-pushed the load-common-const-empty-tuple branch from 84e6f85 to 79cc39d Compare May 11, 2026 15:28
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Copy link
Copy Markdown
Member

There are, inevitably, merge conflicts.
Happy to merge when they're fixed

…ty-tuple

# Conflicts:
#	Include/internal/pycore_opcode_utils.h
#	Lib/opcode.py
#	Python/pylifecycle.c

markshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good

markshannon merged commit f2fa291 into python:main May 21, 2026
104 of 106 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL