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] feat: cache len for iterating over immutable types#19656

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 8 commits intopython:masterfromBobTheBuidler:for-loop-immutable
Aug 14, 2025

Conversation

@BobTheBuidler
Copy link
Contributor

@BobTheBuidlerBobTheBuidler commentedAug 14, 2025
edited
Loading

Currently, if a user uses an immutable type as the sequence input for a for loop, the length is checked once at each iteration which, while necessary for some container types such as list and dictionaries, is not necessary for iterating over immutable types tuple, str, and bytes.

This PR modifies the codebase such that the length is only checked at the first iteration, and reused from there.

L0:
r0 = 'abc'
source = r0
r1 = CPyStr_Size_size_t(source)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

this CPyStr_Size twice in 4 lines thing looks pretty ugly, but its better than what we had before. This will be optimized a bit better in my follow-up PR

Copy link
Collaborator

@JukkaLJukkaL left a comment

Choose a reason for hiding this comment

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

This looks reasonable. I suspect that this will rarely yield any significant performance improvement, but the implementation is simple enough and it could help in the future more once we optimize other things (almost all the change volume is in irbuild tests, which are easier to maintain since they can be updated automatically).

@JukkaLJukkaL merged commitc95d8ab intopython:masterAug 14, 2025
13 checks passed
@BobTheBuidler
Copy link
ContributorAuthor

I did see a ~0.4% improvement when I benchmarked self-check, but that was on the larger PR with the other len-related change as well. In any case the IR looks prettier now!

@BobTheBuidlerBobTheBuidler deleted the for-loop-immutable branchAugust 14, 2025 15:22
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JukkaLJukkaLJukkaL 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

@BobTheBuidler@JukkaL

[8]ページ先頭

©2009-2025 Movatter.jp