Skip to content

Optimization: mark some classes as acyclic#20804

Open
JukkaL wants to merge 1 commit intomasterfrom
use-acyclic
Open

Optimization: mark some classes as acyclic#20804
JukkaL wants to merge 1 commit intomasterfrom
use-acyclic

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 13, 2026

This will save a bit of memory and make instance construction faster. The impact will be hard to measure, possibly under the noise floor, but it should be a slight improvement, and acts as a real-world test case of the new mypyc feature.

This will save a bit of memory and make instance construction faster.
@JukkaL JukkaL requested a review from ilevkivskyi February 13, 2026 14:31
@github-actions
Copy link
Contributor

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

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

There are some cases that may be not correct.

Graph: _TypeAlias = dict[str, "State"]


@mypyc_attr(acyclic=True)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is true, because of direct_dependents that points back to SCC that depends on the current one. This is used to notify dependents when they are ready to be processed.

Copy link
Member

Choose a reason for hiding this comment

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

Actually ignore this one, we refer to direct dependents by id, so we should be good here.

return isinstance(other, UnpackType) and self.type == other.type


@mypyc_attr(acyclic=True)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure we can actually guarantee this. There is source_any that can refer to itself because of a flaw in type inference logic somewhere.

COMPLETE_FEATURES: Final = frozenset((TYPE_VAR_TUPLE, UNPACK, NEW_GENERIC_SYNTAX))


@mypyc_attr(acyclic=True)
Copy link
Member

Choose a reason for hiding this comment

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

Again, _per_module_cache can cause problems in theory. Not sure how dangerous it is.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Feb 13, 2026

I'll review the potential issues and revert anything that I think could realistically be a problem.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

(would be cool if mypy was able to validate use of this to some extent)

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.

3 participants