Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache the construction of "BadType" in case when pytype sees a Bad Ma…
…tch of types. 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 dignostics to indicate which type mismatches, 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 object will stay until the lifetime of the AbstractMatcher which I think the lifetime is same 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. PiperOrigin-RevId: 701062879
- Loading branch information