Talks - Charlie Marsh: Ruff: An Extremely Fast Python Linter and Code Formatter, Written in Rust

Learn how Ruff, a Python linter written in Rust, achieves extreme performance through optimizations, data-driven development, and key architectural decisions.

Key takeaways
  • Ruff is an extremely fast Python linter and code formatter written in Rust, processing Python code significantly faster than traditional tools

  • Performance improvements came from multiple optimizations:

    • Using byte offsets instead of row/column indexing
    • Small integer optimizations to avoid heap allocations
    • Avoiding regular expressions for common operations
    • Parallel processing of files
    • Single-pass analysis versus multiple tool passes
  • Key architectural decisions:

    • Hand-written parser instead of generated parser for better control
    • Stack vs heap memory usage optimization
    • SIMD and data parallelism
    • Common intermediate representation for all rules
    • Focus on avoiding unnecessary allocations
  • Data-driven approach to optimization:

    • Continuous benchmarking on real codebases
    • Profiling to identify bottlenecks
    • Making optimization decisions based on measured data
    • Testing against large real-world projects
  • Success metrics:

    • Over 18 million downloads per month
    • Used by major Python projects like FastAPI, Pandas, SciPy
    • 2x performance improvement over the past year
    • Half a million VS Code extension installs
    • 27,000+ GitHub stars
  • Key principles:

    • Performance as a first-class concern
    • Data-driven decision making
    • Balance between optimization and maintainability
    • Investment in tooling and benchmarking
    • Focus on end-user experience over pure performance gains