Skip to content

Time checkers with and without return type inference - #174

Draft
samwgoldman wants to merge 1 commit into
lolpack:mainfrom
samwgoldman:return-type-inference-variants
Draft

samwgoldman wants to merge 1 commit into
lolpack:mainfrom
samwgoldman:return-type-inference-variants

Conversation

@samwgoldman

@samwgoldman samwgoldman commented Nov 26, 2026 •

Copy link
Copy Markdown

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.

Checker Default Other setting
Pyright on none: there is no setting to turn it off (analyzeUnannotatedFunctions = false also skips checking those functions)
Pyrefly on off: infer-return-types = "never"
ty off on: [analysis] return-type-inference = "always"
mypy off none: mypy never infers return types
Zuban on off: untyped_function_return_mode = any

Runner

  • Every checker still runs in its default configuration, recorded in metrics as before, so older results and anything reading them are unaffected.
  • Pyrefly, ty and Zuban also run with the opposite setting, written into the same generated config. Those runs go in a new alternate_metrics (plus alternate_aggregate), and return_type_inference_default records which setting each default is.
  • --no-alternate-inference skips the extra runs. The two per-package measurement loops (cloned and --local) are now one helper.
  • CI cost: three more checker runs per package, all on the fast checkers.

Dashboard

Layout A, per review: both settings side by side by default, with the Both / Off / On control kept.

  • Summaries: paired bars per checker (hatched = off, solid = on), with a default badge on the setting each checker uses out of the box, in both the paired and single-setting views.
  • Table: two lines per cell (○ off, ● on), n/a where a checker lacks the setting; headers repeat each checker's default.
  • Every setting is compared only with the same setting (the "fastest" marker and the "N×" ratios are per setting), and all summaries use the packages that every checker finished in every setting, so switching views never changes the package set.
  • Off / On (also ?inference=off|on) show one setting at a time, greying out checkers without it (mypy under On, Pyright under Off).
  • Methodology: a note that "on" compares configurations with inference enabled, not identical analysis. For example, ty 1.0 with return-type-inference = "always" still infers nothing for generators or async functions (checked: Unknown and CoroutineType[Any, Any, Unknown]), which Pyrefly and Zuban infer.
  • Results without alternate runs (e.g. today's published 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):

Both: summary
Both: table
Off: summary
On: table
Methodology

Test plan

  • python -m pytest tests/: 554 passed, 1 skipped (new tests/test_typecheck_benchmark_return_inference.py covers the config lines, which checkers get alternate runs, the output JSON and the CLI flag)
  • pyrefly check: 0 errors; npm run check: clean
  • Checked each setting takes effect on a small file (revealed return types change as expected) and on real packages.
  • Full local run of all 53 packages; rendered the page from it in headless Chromium, and from the published results to confirm they render as before.

@lolpack

lolpack commented Nov 28, 2026

Copy link
Copy Markdown
Owner

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.
@samwgoldman
samwgoldman force-pushed the return-type-inference-variants branch from 7d7a10a to 6f9bce4 Compare December 2, 2026 20:33
@sharkdp

sharkdp commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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.

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.

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.

@samwgoldman

Copy link
Copy Markdown
Author

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?

@sharkdp

sharkdp commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

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.

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

Oh, interesting. Thank you for flagging this, I'll look into it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants