gh-118761: Improve import time of the pickle module. (#128732)

Importing `pickle` is now roughly 25% faster.

Importing the `re` module is no longer needed and
thus `re` is no more implicitly exposed as `pickle.re`.

---------

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Bénédikt Tran 2025-01-14 12:26:26 +01:00 committed by GitHub
parent 1153e66e20
commit ff3e145b27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -31,7 +31,6 @@ from functools import partial
import sys
from sys import maxsize
from struct import pack, unpack
import re
import io
import codecs
import _compat_pickle
@ -188,7 +187,7 @@ BYTEARRAY8 = b'\x96' # push bytearray
NEXT_BUFFER = b'\x97' # push next out-of-band buffer
READONLY_BUFFER = b'\x98' # make top of stack readonly
__all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$", x)])
__all__.extend(x for x in dir() if x.isupper() and not x.startswith('_'))
class _Framer:

View file

@ -0,0 +1,3 @@
Improve import time of :mod:`pickle` by 25% by removing an unnecessary
regular expression. As such, :mod:`re` is no more implicitly available
as ``pickle.re``. Patch by Bénédikt Tran.