Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add additional gc benchmark with pickletools (#437)#438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pgdr wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
frompgdr:bm_pickled_opt

Conversation

@pgdr
Copy link

@pgdrpgdr commentedNov 3, 2025
edited
Loading

Adds a benchmark reproducing the Python 3.14 garbage collector regression described incpython/#140175.

This real-world case usespickletools to demonstrate the performance issue.

Fixes#437.

@pgdr
Copy link
Author

pgdr commentedNov 3, 2025
edited
Loading

Python versionRunning time (sec)
3.131.59
3.146.47
3.15a1.55

These tests (and the PR) has N = 1'000'000. The downside is that running the benchmark (with Python 3.14) takes almost 10 minutes.

I could reduce the size of the instance to lower the overall running time, but it seems like the garbage collector bug doesn't "kick in" until we reach a certain size.

With N = 100'000, the slowdown is not as noticable:

Python versionRunning time (ms)
3.13162
3.14197
3.15a154

@pgdr
Copy link
Author

pgdr commentedNov 5, 2025

@sergey-miryanov Thanks for the review. I have fixed all issues you pointed out.

@pgdr
Copy link
Author

pgdr commentedNov 5, 2025

@sergey-miryanov Something strange happens here. Even though I use the context manager (tempfile.TemporaryDirectory), occasionally when I kill pyperformance, the directory remains not cleaned up.

I am not able to reproduce this behavior when not running withpyperf, though, so it might be related to the waypyperf sets up (parallel?) runners.

It sounds like a bug, but I can't tell where.

Copy link

@sergey-miryanovsergey-miryanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Code looks good to me.

@sergey-miryanov
Copy link

@pgdr Thanks! It is up topyperformance maintainers now.

@nascheme
Copy link
Member

These tests (and the PR) has N = 1'000'000. The downside is that running the benchmark (with Python 3.14) takes almost 10 minutes.

Taking 10 minutes would be too long. However, it only takes about 6 seconds for me to run this on Python 3.14.0, on my hardware. Perhaps the 10 minutes is for when N = 10e6? The regression I see from 3.13 to 3.14 with N = 1e6 seems large enough (1.5 seconds vs 6 seconds, roughly).

Nice work on this benchmark. I think it's good becauseoptimize() is doing some meaningful work, unlike some other synthetic benchmarks. In addition to showing this regression in the GC, I would expect this benchmark to catch other kinds of performance regressions.

@nascheme
Copy link
Member

nascheme commentedNov 12, 2025
edited
Loading

Small suggestion: it would be simpler to useio.BytesIO() rather than using real files in a temporary folder. I don't think that affects the usefulness of the benchmark, since we are not really testing real file IO speed. Something like this:

def setup(fp, N):    x = {}    for i in range(1, N):        x[i] = f"ii{i:>07}"    pickle.dump(x, fp, protocol=4)def run(fp):    p = fp.read()    s = pickletools.optimize(p)

You could usedumps() as well and do away with the file.

@pgdr
Copy link
Author

@nascheme Thanks a lot, that saved a whole bunch of complexity. Running some tests and then I'll fix it. Something like this:

importpickleimportpickletoolsimportpyperfdefsetup(N:int)->bytes:x= {i:f"ii{i:>07}"foriinrange(N)}returnpickle.dumps(x,protocol=4)defrun(p:bytes)->None:pickletools.optimize(p)if__name__=="__main__":runner=pyperf.Runner()runner.metadata["description"]="Pickletools optimize"N=100_000payload=setup(N)runner.bench_func("pickle_opt",run,payload)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@sergey-miryanovsergey-miryanovsergey-miryanov approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add additional GC related benchmark

3 participants

@pgdr@sergey-miryanov@nascheme

[8]ページ先頭

©2009-2026 Movatter.jp