Python Type Checker Comparison: Speed and Memory Usage – Pyrefly
16 hours ago
- #type-checking
- #python
- #performance
- New type checkers Pyrefly and Ty, written in Rust, are significantly faster and use less memory than established tools Pyright and Mypy, with up to 10-50x speed improvements on large packages.
- Performance evaluation is based on checking 53 popular open-source Python packages, focusing on execution time and peak memory usage, with Pyrefly and Ty completing checks in seconds compared to minutes for Pyright and Mypy on large projects.
- Key factors affecting performance include implementation language (Rust vs. Python/TypeScript), architectural design, inference features, and codebase characteristics such as size, dependency graphs, unions, and type coverage.
- Pyrefly prioritizes speed and memory efficiency while enabling advanced inference features by default, and it can check massive codebases like Instagram's 20 million lines in about 30 seconds.
- Developers are encouraged to test these tools on their own projects to assess performance, and should consider factors beyond speed, such as typing specification conformance and IDE support, when choosing a type checker.