Skip to content

[mypyc] Support explicit acyclic native classes that avoid gc#20795

Merged
JukkaL merged 3 commits intomasterfrom
mypyc-acyclic
Feb 13, 2026
Merged

[mypyc] Support explicit acyclic native classes that avoid gc#20795
JukkaL merged 3 commits intomasterfrom
mypyc-acyclic

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 13, 2026

Use @mypyc_attr(acyclic=True) so that instances of the class don't
participate in cyclic gc. This sped up a microbenchmark that just
allocates lots of temporary objects by ~60%. Acyclic instances also
use less memory, since there is no GC header.

I did some manual testing beyond the added tests to ensure acyclic
classes work as expected.

We can later add support for inferring acyclicity automatically in some
cases, but usually it will have to be explicitly declared.

This was created using Claude Code.

Use `@mypyc_attr(acyclic=True)` so that instances of the class don't
participate in cyclic gc. This sped up a microbenchmark that just
allocates lots of temporary objects by ~60%. Acyclic instances also
use less memory, since there is no GC header.

I did some manual testing beyond the added tests to ensure acyclic
classes work as expected.

This was created using Claude Code.
@JukkaL JukkaL merged commit d422b3d into master Feb 13, 2026
17 checks passed
@JukkaL JukkaL deleted the mypyc-acyclic branch February 13, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants