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

[mypyc] Allow defining a single-item free "list" for a native class#19785

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

Merged
JukkaL merged 3 commits intomasterfrommypyc-free-list-attr
Sep 2, 2025

Conversation

@JukkaL
Copy link
Collaborator

It's quite common to have a class where we almost always have at most a single allocated instance (per thread). Now these instances can be allocated more quickly, by reusing the memory that was used for the most recently freed instance (a separate memory block is reused for each thread on free-threaded builds).

It's used like this (only the value 1 is supported for now):

from mypy_extensions import mypyc_attr@mypyc_attr(free_list=1)class Foo:    ...

This makes a microbenchmark that only allocates and immediately frees simple objects repeatedly around 3.8x faster.

It's probably worth extending this to support larger free lists in the future.

We can later look into enabling this automatically for certain native classes based on profile information.

JukkaLand others added2 commitsSeptember 2, 2025 10:55
It's quite common to have a class where we almost always have at mosta single allocated instance (per thread). Now these instances can beallocated more quickly, by reusing the memory that was used for themost recently freed instance (a separate memory block is reused foreach thread on free-threaded builds).It's used like this (only the value 1 is supported for now):```from mypy_extensions import mypyc_attr@mypyc_attr(free_list=1)class Foo:    ...```This makes a microbenchmark that only allocates and immediatelyfrees simple objects repeatedly around 3.8x faster.It's probably worth extending this to support larger free lists in thefuture.We can later look into enabling this automatically for certain nativeclasses based on profile information.
@JukkaLJukkaL merged commite35e05f intomasterSep 2, 2025
13 checks passed
@JukkaLJukkaL deleted the mypyc-free-list-attr branchSeptember 2, 2025 12:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@p-sawickip-sawickip-sawicki approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@JukkaL@p-sawicki

[8]ページ先頭

©2009-2025 Movatter.jp