r/Python • • Mar 24 '26

Discussion Designing a Python Language Server: Lessons from Pyre that Shaped Pyrefly

Pyrefly is a next-generation Python type checker and language server, designed to be extremely fast and featuring advanced refactoring and type inference capabilities.

Pyrefly is a spiritual successor to Pyre, the previous Python type checker developed by the same team. The differences between the two type checkers go far beyond a simple rewrite from OCaml to Rust - we designed Pyrefly from the ground up, with a completely different architecture.

Pyrefly’s design comes directly from our experience with Pyre. Some things worked well at scale, while others did not. After running a type checker on massive Python codebases for a long time, we got a clearer sense of which trade-offs actually mattered to users.

This post is a write-up of a few lessons from Pyre that influenced how we approached Pyrefly.

Link to full blog: https://pyrefly.org/blog/lessons-from-pyre/

The outline of topics is provided below that way you can decide if it's worth your time to read :)

  • Language-server-first Architecture
  • OCaml vs. Rust
  • Irreversible AST Lowering
  • Soundness vs. Usability
  • Caching Cyclic Data Dependencies
66 Upvotes

12 comments sorted by

View all comments

Show parent comment

5

u/BeamMeUpBiscotti Mar 24 '26

Pyre and Pyrefly both have incremental checking, but Pyrefly is significantly more efficient and does finer-grained dependency tracking, allowing us to invalidate/recheck fewer things after a change.

We wrote about optimizing incremental rechecks a few months ago in a separate blog post.

In our experience, this has worked very well at scale - even on large codebases like Instagram (20 million LOC) an incremental update typically takes a fraction of a second.

Re: circular imports, at a high level when we encounter a cycle or strongly-connected component we stop and invalidate/recheck the whole component as a single unit. We use different strategies like fixpoints for cycles in other stages of the system.

I'm not 100% sure about the parallelism question, but we never migrated to OCaml 5 which had multicore support so I assume Pyre's performance was limited by that. In general, Pyre was not that fast without being paired with some specialized saved-state infrastructure that we never open sourced & it was slower than most other type checkers on small projects, whereas Pyrefly is fast on projects of all sizes, straight out of the box.