Skip to content

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

Open
@pranavrajpal

Description

@pranavrajpal

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).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions