Skip to content

gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT#149688

Open
eendebakpt wants to merge 1 commit intopython:mainfrom
eendebakpt:load-common-const-empty-tuple
Open

gh-148871: Add CONSTANT_EMPTY_TUPLE to LOAD_COMMON_CONSTANT#149688
eendebakpt wants to merge 1 commit intopython:mainfrom
eendebakpt:load-common-const-empty-tuple

Conversation

@eendebakpt
Copy link
Copy Markdown
Contributor

@eendebakpt eendebakpt commented May 11, 2026

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
Copy link
Copy Markdown

python-cla-bot Bot commented May 11, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@eendebakpt eendebakpt force-pushed the load-common-const-empty-tuple branch from 84e6f85 to 79cc39d Compare May 11, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant