plasma-umass/scalene

Scalene: a high-performance, high-precision CPU, GPU, and memory profiler for Python with AI-powered optimization proposals

What it solves

Scalene is a high-performance profiler for Python that identifies bottlenecks in CPU, GPU, and memory usage. It solves the problem of imprecise or slow profiling by providing line-level detail and separating time spent in Python code from time spent in native libraries or system I/O, allowing developers to focus on the code they can actually optimize.

How it works

Scalene uses sampling instead of instrumentation to keep overhead low (typically 10-20%). It tracks CPU usage, NVIDIA GPU time, and memory allocations via a specialized memory allocator. It also attributes await time for async coroutines and captures stitched Python and native (C/C++) call stacks. To provide optimization suggestions, it integrates with AI providers like OpenAI, Azure, Amazon Bedrock, and Ollama.

Who it’s for

It is designed for Python developers who need to optimize the performance of their applications, particularly those using heavy native libraries, asynchronous code, or GPU acceleration.

Highlights

  • AI-Powered Optimizations: Generates proposed code improvements using LLMs based on the profiled data.
  • Detailed Resource Tracking: Separates Python, native, and system time, and identifies memory leaks and copying volume.
  • Comprehensive Visualizations: Includes a web-based GUI with flame charts for call stacks, memory-weighted stacks, and a wall-clock timeline.
  • Async Profiling: Measures per-line wall-clock attribution for suspended coroutines and tracks concurrency levels.
  • Low Overhead: Runs significantly faster than many other profilers while maintaining high accuracy.

Related

  • Project
  • Project
  • Dispatch
  • Project
  • Project