Skip to content

Avoid type checking dependencies when errors aren't reported #12854

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

Open
pranavrajpal opened this issue May 23, 2022 · 2 comments
Open

Avoid type checking dependencies when errors aren't reported #12854

pranavrajpal opened this issue May 23, 2022 · 2 comments

Comments

@pranavrajpal
Copy link
Contributor

Feature

When we're type checking code that we aren't going to report errors for (like any code in site-packages), we can improve performance by avoiding doing most of the work of type checking.

Pitch

I tried type checking mypy with an uncompiled mypy from master (19e9f21) itself using this command:

mypy mypy mypyc --config-file mypy_self_check.ini --no-incremental --timing-stats timing_data.txt

The results I got using the per-file timing stats were that of the approximately 63.6 seconds spent type checking, 44.3 seconds were spent type checking modules in mypy or mypyc, and the remaining 19.3 seconds were spent in other modules.

While 19.3 seconds isn't a majority of the build time, it is still a not insignificant amount of time spent type checking dependencies, even though that work will mostly get thrown away since we don't report errors in any of those dependencies.

There are probably a couple things we can skip doing for code that doesn't have errors reported:

  1. Avoid semantic analysis and type checking inside functions, since that shouldn't affect what other modules see.
  2. Skip particularly expensive checks at module level when type checking (we can't really completely skip type checking because we probably still need to run type inference on that code, and I think we group those together).
  3. Avoid loading modules that are never used directly in the code being checked (currently we sometimes analyze modules that are imported directly or indirectly by another dependency module that is directly used in checked code).
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented May 23, 2022

Yeah, very much agreed. For work in the line of 2, see #10922, which was like a 2x overall speedup.

@hauntsaninja
Copy link
Collaborator

#14150 removes a big chunk of unnecessary work. Curious for what our approach to your item 3 would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants