Repository navigation
Extend and improve LOAD_COMMON_CONSTANT #148871
Copy link
Copy link
Open
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
Activity
- addedperformancePerformance or resource usagePerformance or resource usageinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Apr 22, 2026 - addedtype-featureA feature request or enhancementA feature request or enhancement
on Apr 22, 2026 - added 5 commits that reference this issue
on Apr 26, 2026 Now #148971 is merged, we need to make
LOAD_COMMON_CONSTANTfast.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_CONSTANTbecomesvalue = tstate->interp->common_consts[oparg];Without any need to handle refcounts.
- added a commit that references this issue
on May 11, 2026 - added a commit that references this issue
on May 21, 2026 - added a commit that references this issue
on May 28, 2026
Metadata
Metadata
Assignees
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
Currently
LOAD_COMMON_CONSTANTonly loads 7 not-so-common constants and does so fairly inefficiently.It could be improved in two ways:
None, but also"",True,Falseand-1Make the constants that it does load both statically allocated and immortal to avoid the pointer chasing and incref operation. Onlyanyandallwould need changing.After some consideration, I think it best to leave the common constants table per interpreter, and not statically allocate them.
anyandallmay be breaking.AssertionErrorandNotImplementedErrorwill be tricky to make staticThey should all be immortal though, and stored as
_PyStackRefs notPyObject *s.Linked PRs
LOAD_COMMON_CONSTANT#148971LOAD_COMMON_CONSTANTuse immortal stackref borrows #149625