This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Increase the information content and robustness of tp_version_tag.
Type: performance Stage:
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, brandtbucher
Priority: normal Keywords:

Created on 2021-10-21 10:16 by Mark.Shannon, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg404580 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-10-21 10:16
Currently, we use the `tp_version_tag` as a proxy for the state of a class when specializing.
When we have issued 2**32 tags, we stop issuing tags. This prevents specializing of classes that need a new tag.

We can make a few enhancements:

1. Reserve the low 2**M (M probably 4 or 5) values for special classes. This would allow us to perform some type checks efficiently in a multiple-interpreter environment.
`PyLongCheck_Exact(ob)` is currently `Py_TYPE(ob) == &PyLong_Type` but could become `Py_TYPE(ob)->tp_version_tag == PY_INT_VERSION_TAG`. No need to access the interpreter state.

2. Reserve the low 2**N (N somewhere in range 10 to 16) for builtin classes. Maybe split this into immutable and mutable. 
We often need to load the version tag, this would save another load from tp_flags to check for builtin-ness and (im)mutability.

3. Add a modified count to the type struct. When this reaches a threshold, no longer issue tags for this class.
This would prevent pathological classes consuming millions of tags. Only needs 16 bits.

The reason we want power of two boundaries is so that we can test multiple types at once.
E.g. T1 and T2 are both "special" if `(T1->tp_version_tag | T2->tp_version_tag) < 2**M`
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89713
2021-11-11 00:16:38Mark.Shannonsetnosy: + brandtbucher
2021-10-21 10:16:53Mark.Shannoncreate