Skip to content

[mypyc] Borrow generator frame state more aggressively - #21987

Merged
JukkaL merged 14 commits into
masterfrom
mypyc-generator-opt-borrow
Sep 15, 2026
Merged

JukkaL merged 14 commits into
masterfrom
mypyc-generator-opt-borrow

Conversation

@JukkaL

@JukkaL JukkaL commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

The frame is private, and the generator running flag prevents another helper invocation from accessing it concurrently, so attribute values can be borrowed while the helper runs. This is particularly helpful on free-threaded builds, since reference counting is expensive.

I checked that this speeds up some microbenchmarks, from 1.04x to 1.8x on Python 3.14.

I used coding agent assist but did many iterative improvements.

) -> None:
self.self_reg = self_reg
self.candidates = candidates
self.candidates_by_attr = candidates_by_attr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

make these Final?

@JukkaL
JukkaL merged commit 265a5a3 into master Sep 15, 2026
18 checks passed
@JukkaL
JukkaL deleted the mypyc-generator-opt-borrow branch September 15, 2026 12:28
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