PEP 509 introduced a privatema_version_tag field for dictionaries toallow optimizations in CPython and extension libraries. This PEP proposes torescindPEP 509 and declare the field an implementation detail, as it hasalready been superseded by alternatives. This will further allow the field tobe reused for future optimization.
PEP 509 introduced thema_version_tag field to dictionaries. This 64-bitfield stored a version counter that updates every time a dictionary wasmodified. The original proposal was to use this version counter as aguard for optimizations.
Since CPython 3.11, this field has become unused by internal optimizationefforts.PEP 659-specialized instructions use other methods of verifyingthat certain optimizations are safe.
To enable further optimizations in CPython, this PEP proposes that thema_version_tag field no longer conform to thePEP 509 specification.This will allow the CPython developers to store other optimization information,such as dictionary write watchers.
This PEP does not specify what the field may be used for in the future. This isintentional, as implementation details are subject to change, and the fieldshould be used only for internal consumption by CPython.
This specification rescinds that inPEP 509. Thema_version_tag field ofthe Pythondict class is declared to be an internal implementationdetail and may be removed altogether, or may have a different representation.C extensions should not rely on this field.
Certain extensions usema_version_tag for fast dictionary or globalslookups. For example,Cython uses the field for fast dynamic module variable lookups.
This PEP proposes to emit a compiler warning when accessingma_version_tag.After two consecutive version releases with warnings,ma_version_tagwill be removed, in line withPEP 387.
The biggest user the author could find for this field was Cython.Discussions with a Cython maintainer indicated thatremoving support for it from Cython is trivial.
PEP 509 was concerned with integer overflow. However, this PEP does notintroduce any additional security concerns.
A possible alternative is to preserve the field for backwards compatibility.This PEP rejects that alternative as future optimizations will consume morememory, and the field was always considered private and undocumented asidefrom the PEP, with no backward compatibility guarantees. Dictionaries in Pythonare commonly used, and any increase in their memory consumption will adverselyaffect Python’s performance.
A reference implementation can be found inpython/cpython#101193.
Thanks to C.A.M. Gerlach for edits and wording changes to this document.Thanks also to Mark Shannon and Kumar Aditya for providing possibleimplementations.
This document is placed in the public domain or under theCC0-1.0-Universal license, whichever is more permissive.
Source:https://github.com/python/peps/blob/main/peps/pep-0699.rst
Last modified:2025-02-01 08:55:40 GMT