python / python/mypy

Avoid type checking dependencies when errors aren't reported

Offen
#12,854 2 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature performance
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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 (19e9f2136fd46c662f1066a4894edf48173942f4) 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).

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das Problem mit dem bereitgestellten mypy-Befehl und der Ausgabe von timing-stats zu reproduzieren, und vergleiche dann die für die Überprüfung von Abhängigkeiten aufgewendete Zeit mit der für Code, dessen Fehler gemeldet werden. Die Arbeit ist abgeschlossen, wenn die nicht gemeldete Überprüfung von Abhängigkeiten reduziert wurde, ohne die Diagnosen oder die erforderlichen Typinformationen für direkt überprüften Code zu ändern.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.