You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pathlib.PurePath.__reduce__() currently accesses and returns the parts tuple. Pathlib ensures that the strings therein are interned.
There's a good reason to do this: it ensures that the pickled data is as small as possible, with maximum re-use of small string objects.
However, it comes with some disadvantages:
When normalising any path, we need to call sys.intern(str(part)) on each part
When pickling a path, we must join, parse and normalise, and then generate the parts tuple.
We could instead make __reduce__() return the raw paths fed to the constructor (the _raw_paths attribute). This would be faster but less space efficient. With the cost of storage and bandwidth falling at a faster rate than compute, I suspect this trade-off is worth making.
Activity
pythonGH-112855: Speed up `pathlib.PurePath` pickling
pythonGH-112855: Slightly improve tests for `pathlib.PurePath` pickling
Merge branch 'main' into pythongh-112855-improve-path-pickle-tests
GH-112855: Slightly improve tests for `pathlib.PurePath` pickling (#1…
pythonGH-112855: Slightly improve tests for `pathlib.PurePath` pickli…
pythonGH-112855: Slightly improve tests for `pathlib.PurePath` pickli…
pythonGH-112855: Slightly improve tests for `pathlib.PurePath` pickli…
GH-112855: Speed up `pathlib.PurePath` pickling (#112856)
pythonGH-112855: Slightly improve tests for `pathlib.PurePath` pickli…