astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33.22k stars 1.11k forks source link

[red-knot] Add a benchmark involving realistic code that creates large unions #13549

Open AlexWaygood opened 2 months ago

AlexWaygood commented 2 months ago

Code that creates large unions (explicitly or implicitly) is known to be hard for type checkers to analyze in a performant way. Both mypy and pyright have had lots of issues regarding performance for these, and both have implemented several optimizations to deal with them. We should add at least one benchmark (probably several) that measures how we do on this.

Common themes that come up in this area are:

References

Here are some references that are worth looking at (and from which we might be able to derive benchmarks). The great thing about all of these is that they are performance issues that we know real users encountered when their type checker was checking real code. I've tried to exclude anything specific to recursive type aliases, since that feels somewhat out of scope for this issue:

Mypy

Pyright

dangotbanned commented 2 months ago

We recently added a TypedDict-heavy feature in altair.

Not sure if this helps as real-world examples, but sharing as red-knot came up during review

mypy performance here has a lot of room for improvement

hauntsaninja commented 1 month ago

Nice! I'll add altair to mypy_primer. You may also be interested in https://github.com/python/mypy/issues/17231#issuecomment-2379375287 , I think it makes mypy significantly faster on your workload.