Skip to content

Commit

Permalink
gh-118761: Improve import time of the pickle module. (#128732)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
picnixz and AA-Turner authored Jan 14, 2025
1 parent 1153e66 commit ff3e145
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import sys
from sys import maxsize
from struct import pack, unpack
import re
import io
import codecs
import _compat_pickle
Expand Down Expand Up @@ -188,7 +187,7 @@ def __init__(self, value):
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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit ff3e145

Please sign in to comment.