Repository navigation
Time checkers with and without return type inference - #174
samwgoldman wants to merge 1 commit into
Conversation
|
This seems like a useful addition. My preference is A with the Both/Off/On controls retained. The paired bars make the inference cost visible, and the stacked table is easier to scan than the separate columns. I’d make each checker’s default more prominent in the summary charts, too; currently that information is clearest in the table headers. One methodology clarification: “on” doesn’t mean identical inference coverage across tools. For example, ty currently excludes async functions and generators even with return-type-inference = "always". A short note would help readers interpret these as comparisons of configurations with inference enabled, without implying equivalent analysis. Longer term, I wonder if there is a way to communicate and benchmark all of the major features impacting performance. |
Checkers differ on whether they infer the return types of unannotated functions: Pyright, Pyrefly and Zuban do by default, ty and mypy don't. That difference is part of what the timing comparison measures, but the page gave no way to separate it from everything else. Pyrefly, ty and Zuban can switch the setting, so the runner now also times each of them with the opposite of its default, written to the same generated config (`infer-return-types = "never"`, `[analysis] return-type-inference = "always"`, `untyped_function_return_mode = any`). Pyright has no setting to turn inference off and mypy never infers return types, so each runs in one setting only. The default runs stay in `metrics`, so older results and their readers are unaffected; the new runs go in `alternate_metrics`, and `return_type_inference_default` records which setting each default is. `--no-alternate-inference` skips the extra runs. The dashboard shows both settings by default: paired bars in the summaries and two lines per cell in the package table, each setting compared only with the same setting, with each checker's default marked. A Both/Off/On control shows one setting at a time, with checkers that lack it greyed out. The methodology notes that "on" compares configurations, not identical analysis. Results without alternate runs render as before.
7d7a10a to
6f9bce4
Compare
|
I definitely agree that we should try to make the comparisons as fair as possible. But I would personally prefer to generally switch it on for all type-checkers (and maybe add a comment somewhere that this is not something that all type-checkers implement), or to switch it off for all type-checkers (as far as possible). If we start to split benchmarks by enabled features, we're opening a rabbit hole. Or do we also want to compare type-checkers based on which rules they activate? Some checks might be very expensive and other type checkers might just not implement them. To give another example: I believe both Pyrefly and ty check Jupyter notebooks by default, whereas other type-checkers just ignore them. Similarly, PEP 723 scripts in projects might soon be checked by ty by default (which might require expensive environment provisioning). Again, we could certainly try to make the comparison as fair as possible by disabling/enabling features, but I'd rather not expand the benchmark matrix for each of these features. I think the value of this project lies in (1) its independence and (2) its simplicity, which are good for users who want a brief overview.
It's true that ty doesn't yet infer return types for async functions and generators, but I don't think it's very useful to list every tiny missing feature on this page. I think we just have to accept the fact that this comparison will never be completely fair. Users should not just pick their type checker based on these results. Similar to how they should not decide based on conformance score. Or otherwise they would all choose https://github.com/JelleZijlstra/ultrafast. |
|
Thanks for weighing in, @sharkdp! In practice, it doesn't seem to make a big difference (except that ty w/ return type inference hangs on tensorflow, I haven't confirmed). I couldn't find a setting to disable return type inference for Pyright, so if we just showed "off" then we might penalize Pyright unfairly. My inclination is to turn it on and note that mypy does not support it. How does that sound? |
That sounds good to me. I plan to add support for async/generator functions soon, which should make the comparison more fair.
Oh, interesting. Thank you for flagging this, I'll look into it. |
Checkers differ on whether they infer the return types of functions without a return annotation. That is a real part of the cost difference between them, so this measures it separately.
analyzeUnannotatedFunctions = falsealso skips checking those functions)infer-return-types = "never"[analysis] return-type-inference = "always"untyped_function_return_mode = anyRunner
metricsas before, so older results and anything reading them are unaffected.alternate_metrics(plusalternate_aggregate), andreturn_type_inference_defaultrecords which setting each default is.--no-alternate-inferenceskips the extra runs. The two per-package measurement loops (cloned and--local) are now one helper.Dashboard
Layout A, per review: both settings side by side by default, with the Both / Off / On control kept.
n/awhere a checker lacks the setting; headers repeat each checker's default.?inference=off|on) show one setting at a time, greying out checkers without it (mypy under On, Pyright under Off).return-type-inference = "always"still infers nothing for generators or async functions (checked:UnknownandCoroutineType[Any, Any, Unknown]), which Pyrefly and Zuban infer.latest-ubuntu.json) render exactly as before.Renders from a local run of all 53 packages with Pyright 1.1.414, Pyrefly 1.5.1, ty 1.0.0, mypy 2.4.1, Zuban 0.11.1 (each group pinned to 4 CPUs on a dev machine, 1 warmup + 1 run, so absolute numbers aren't comparable with the published CI results):
Test plan
python -m pytest tests/: 554 passed, 1 skipped (newtests/test_typecheck_benchmark_return_inference.pycovers the config lines, which checkers get alternate runs, the output JSON and the CLI flag)pyrefly check: 0 errors;npm run check: clean