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

Micro-optimize ExpandTypeVisitor#19461

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 1 commit intomasterfromopt-3
Jul 17, 2025
Merged

Micro-optimize ExpandTypeVisitor#19461

JukkaL merged 1 commit intomasterfromopt-3
Jul 17, 2025

Conversation

@JukkaL
Copy link
Collaborator

Specialize a hot for loop for the concretetuple andlist types. Also add a fast path for empty type arguments.

The approach is similar to what I used in#19459.

This is a part of a set of micro-optimizations that improve self check performance by ~5.5%.

Specialize a hot for loop for the concrete `tuple` and `list` types.Also add a fast path for empty type arguments.The approach is similar to what I used in#19459.This is a part of a set of micro-optimizations that improve self checkperformance by ~5.5%.
@JukkaLJukkaL requested a review fromilevkivskyiJuly 16, 2025 13:10
@github-actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

items.append(item.accept(self))
returnitems

defexpand_type_tuple_with_unpack(self,typs:tuple[Type, ...])->list[Type]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, it's an interesting optimization I'd never think of. Is this difference significant because of some list operations special-cased by mypyc (something like bypassing__getitem__ and dispatching toPyList_GetItem directly)?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yeah, mypyc uses specialized primitives for the most common built-in types, includinglist andtuple.@jhance has a WIP implementation of a faster sequence iteration implementation, but narrower types are still going to be at least a little more efficient. The specialized operations are listed in the docs -- here are the ones forlist:https://mypyc.readthedocs.io/en/latest/list_operations.html

@JukkaLJukkaL merged commit5f5871d intomasterJul 17, 2025
20 checks passed
@JukkaLJukkaL deleted the opt-3 branchJuly 17, 2025 09:10
defvisit_instance(self,t:Instance)->Type:
args=self.expand_types_with_unpack(list(t.args))
iflen(t.args)==0:
# TODO: Why do we need to create a copy here?
Copy link
Member

Choose a reason for hiding this comment

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

@JukkaL It is safer to always create new types inexpand_type() as the caller may sometimes modify the existing type in-place (at least it was the case in the past).

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

Reviewers

@ilevkivskyiilevkivskyiilevkivskyi left review comments

+1 more reviewer

@sterliakovsterliakovsterliakov 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.

3 participants

@JukkaL@ilevkivskyi@sterliakov

[8]ページ先頭

©2009-2025 Movatter.jp