Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the result of sub_one_annotation which happens during the construction of "BadType". Also update types on the signatures along the way. #1846

Closed
wants to merge 0 commits into from

Conversation

copybara-service[bot]
Copy link

@copybara-service copybara-service bot commented Nov 29, 2024

Cache the result of sub_one_annotation which happens during the construction of "BadType". Also update types on the signatures along the way.

When a bad match of type happens, it doesn't necessarily mean that there would be a type error. It means that out of many possible signature matches (or type matches) between different types including generics, there is something that doesn't match and we cannot use that result. This result will be used later when producing diagnostics to indicate which pair of types mismatch, in the case where there is no single type match out of those combinations.

The problem is that when the combinations (e.g. multiple signatures, generics, recursive types) that needs to be verified need to be type checked, it tries out so many different combinations of types, and generate tons of the same "BadMatch" which is just redundant. Making it even worse, it's not only the computation but also the memory pressure caused by this because it seems to construct something which is memory intensive, thus GC frequently showing up in profile in these particular cases.

There is still some risk that this might increase the peak memory consumption because once put in the cache, the objects will have the same lifetime as the type checker, but the drastic performance improvement in these particular cases seem worth it.

A better solution might be actually making the type checker not call into generating these seemingly redundant type checks on these crazy combinations, but at a glance this seemed like a fundamental design issue that lives in the complex nature of the type graph, and without being able to understand / changing it this seems to be the shortest path without hurting code health too much.

@copybara-service copybara-service bot changed the title Cache the construction of "BadType" in case when pytype sees a Bad Match of types. Cache the result of sub_one_annotation which happens during the construction of "BadType". Also update types on the signatures along the way. Nov 29, 2024
@copybara-service copybara-service bot force-pushed the cl/701062879 branch 2 times, most recently from 3014fbe to 99c2c37 Compare December 3, 2024 12:49
@copybara-service copybara-service bot closed this Dec 3, 2024
@copybara-service copybara-service bot deleted the cl/701062879 branch December 3, 2024 13:21
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.

0 participants