PEP 699: Remove private dict version field added in PEP 509 (#2811)
Remove private dict version field added in PEP 509
This commit is contained in:
parent
80c69055a5
commit
f4f58d4250
|
@ -579,6 +579,7 @@ pep-0695.rst @gvanrossum
|
|||
pep-0696.rst @jellezijlstra
|
||||
pep-0697.rst @encukou
|
||||
pep-0698.rst @jellezijlstra
|
||||
pep-0699.rst @Fidget-Spinner
|
||||
# ...
|
||||
# pep-0754.txt
|
||||
# ...
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
PEP: 699
|
||||
Title: Remove private dict version field added in PEP 509
|
||||
Author: Ken Jin <kenjin@python.org>
|
||||
Discussions-To:
|
||||
Status: Draft
|
||||
Type: Standards Track
|
||||
Content-Type: text/x-rst
|
||||
Created: 03-Oct-2022
|
||||
Python-Version: 3.12
|
||||
Post-History:
|
||||
Replaces: 509
|
||||
Resolution:
|
||||
|
||||
|
||||
|
||||
Abstract
|
||||
========
|
||||
|
||||
:pep:`509` introduced a private ``ma_version_tag`` field for dictionaries to
|
||||
allow optimizations in CPython and extension libraries. This PEP proposes to
|
||||
rescind :pep:`509` and declare the field an implementation detail, as it has
|
||||
already been superseded by alternatives. This will further allow the field to
|
||||
be reused for future optimization.
|
||||
|
||||
|
||||
Motivation
|
||||
==========
|
||||
|
||||
:pep:`509` introduced the ``ma_version_tag`` field to dictionaries. This 64-bit
|
||||
field stored a version counter that updates every time a dictionary was
|
||||
modified. The original proposal was to use this version counter as a
|
||||
guard for optimizations.
|
||||
|
||||
Since CPython 3.11, this field has become unused by internal optimization
|
||||
efforts. :pep:`659`-specialized instructions use other methods of verifying
|
||||
that certain optimisations are safe.
|
||||
|
||||
To enable further optimizations in CPython, this PEP proposes that the
|
||||
``ma_version_tag`` field no longer conform to the :pep:`509` specification.
|
||||
This will allow the CPython developers to store other optimization information,
|
||||
such as dictionary write watchers.
|
||||
|
||||
|
||||
Rationale
|
||||
=========
|
||||
This PEP does not specify what the field may be used for in the future. This is
|
||||
intentional, as implementation details are subject to change, and the field
|
||||
should be used only for internal consumption by CPython.
|
||||
|
||||
|
||||
Specification
|
||||
=============
|
||||
|
||||
This specification rescinds that in :pep:`509`. The ``ma_version_tag`` field of
|
||||
the Python :class:`dict` class is declared to be an internal implementation
|
||||
detail and may be removed altogether, or may have a different representation.
|
||||
C extensions should not rely on this field.
|
||||
|
||||
|
||||
Backwards Compatibility
|
||||
=======================
|
||||
|
||||
Certain extensions use ``ma_version_tag`` for fast dictionary or globals
|
||||
lookups. For example,
|
||||
`Cython uses the field for fast dynamic module variable lookups <https://github.com/cython/cython/blob/169876872f3cb6198971a1db07e5b8a9d12b3dac/Cython/Utility/ObjectHandling.c#L1556>`_.
|
||||
|
||||
Since this field is private and makes no guarantees on backwards compatibility,
|
||||
this PEP proposes to repeal :pep:`509` immediately within the next CPython
|
||||
version. A function for fast cached dictionary lookups may be provided as an
|
||||
alternative feature to replace directly accessing ``ma_version_tag``.
|
||||
|
||||
The biggest user the author could find for this field was Cython.
|
||||
Discussions with a Cython maintainer indicated that
|
||||
`removing support for it from Cython is trivial <https://github.com/faster-cpython/ideas/issues/461#issuecomment-1250358596>`_.
|
||||
|
||||
|
||||
Security Implications
|
||||
=====================
|
||||
|
||||
:pep:`509` was concerned with integer overflow. However, this PEP does not
|
||||
introduce any additional security concerns.
|
||||
|
||||
|
||||
Rejected Ideas
|
||||
==============
|
||||
|
||||
A possible alternative is to preserve the field for backwards compatibility.
|
||||
This PEP rejects that alternative as future optimizations will consume more
|
||||
memory, and the field was always considered private and undocumented aside
|
||||
from the PEP, with no backward compatibility guarantees. Dictionaries in Python
|
||||
are commonly used, and any increase in their memory consumption will adversely
|
||||
affect Python’s performance.
|
||||
|
||||
|
||||
Special Thanks
|
||||
==============
|
||||
|
||||
Thanks to C.A.M. Gerlach for edits and wording changes to this document.
|
||||
|
||||
|
||||
Copyright
|
||||
=========
|
||||
|
||||
This document is placed in the public domain or under the
|
||||
CC0-1.0-Universal license, whichever is more permissive.
|
||||
|
||||
|
Loading…
Reference in New Issue