Skip to content

pickletools optimize performance degraded with factor 3-4 in python 3.14#140175

@dirkroorda

Description

@dirkroorda

Bug report

Bug description:

The pickletools.optimize code suddenly performs bad starting with python 3.14, with or without JIT.
The degradation is a factor 3 to 4.

It is easy to test.

First use this script to make a sizeable dict and pickle it and write it to file.

importpicklex={} foriinrange(1, 1000000): x[i] =f"ii{i:>07}"withopen("pickled", "wb") asfh: pickle.dump(x, fh, protocol=4)

Then write a script, let's call it optpickle.py to read the pickled dict from file and optimize it and write the result to another file.

# optpickle.pyimportpickletoolswithopen("pickled", "rb") asfh: p=fh.read() s=pickletools.optimize(p) withopen("pickledopt", "wb") asfh: fh.write(s)

Now execute this in three separate terminal windows, one geared to python 3.13, one to python 3.14.0 without JIT, and one to python 3.14.0 with JIT.

My results on a mac with M1 processor were

versiontime elapsedcpu time
3.131.671.773
3.14.0 no JIT6.526.664
3.14.0 JIT6.526.642

That is a dramatic drop in performance!

The filesizes are 16.9 MB for the unoptimized file and 15.9 for the optimized one.

I decided to drop the optimization in an app where I used it heavily

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions