Scalene is a high-performance, high-precision CPU, GPU, and memory profiler for Python. It uses sampling techniques, typically runs with no more than 10-20% overhead, and can provide detailed performance data at the line and function levels.
Purpose: Scalene helps developers locate performance bottlenecks in Python programs, including CPU time, memory allocation, GPU usage (currently limited to NVIDIA systems), system time, and asynchronous wait time. It can also identify possible memory leaks and unexpected copy operations. In addition, Scalene is the first profiler to integrate AI optimization suggestions, and can request optimization solutions from AI providers based on profiling results.
Main capabilities:
- CPU, GPU, and memory profiling, with support for line-level and function-level reports.
- Distinguishes time consumed by Python code versus native code, as well as system time.
- Memory profiling includes per-line memory usage, memory trends, copy volume detection, and leak identification.
- Asynchronous profiling: supports attribution of await time and displays the number of concurrent coroutines.
- Stack views: provides call stacks, memory flame graphs, and timeline views, combining Python and native C/C++ frames.
- AI optimization suggestions: supports Amazon Bedrock, Microsoft Azure, OpenAI, and local Ollama models; click the lightning bolt symbol to generate optimization suggestions.
- Supports the @profile decorator, programmatic control of profiling, reduced output profiles, and more.
- Supports multithreading, multiprocessing (multiprocessing is unique to Scalene), and free-threaded Python (3.13t/3.14t).
- Provides a command-line interface and a web-based GUI (fully available offline), and can generate standalone HTML files.
- Can be used as a VS Code extension, and also supports Jupyter notebooks.
Usage:
Installation: can be installed via pip or conda. After installation, the command-line tool can be used; the main commands are scalene run(run profiling) and scalene view(view results). Supports YAML configuration files, and command-line arguments can override the configuration.
AI optimization: In the GUI's "AI Optimization Options", select a provider and enter credentials (can also be prefilled from environment variables via scalene view --api-keys-from-env ), then click the lightning bolt symbol next to a line or the explosion symbol next to a region to generate optimization suggestions.
VS Code: Install the Scalene extension from the Marketplace, and run it by selecting "Scalene: AI-powered profiling..." from the command palette.
Jupyter: Supports use in Jupyter; see the example notebook for details.
Use cases: Scalene is suitable for developers who need to deeply optimize the performance of Python programs, especially for handling CPU-intensive, memory-intensive, or asynchronous applications. It can help identify hotspots in code, memory leaks, and inefficient copies, and gain optimization ideas through AI suggestions.
Limitations:
- GPU profiling currently only supports NVIDIA systems.
- Windows users need to install the Visual C++ Redistributable, and building from source requires Visual C++ Build Tools and CMake.
- AI optimization suggestions require users to provide their own credentials for the selected AI provider; specific fees and pricing are not currently provided.
- Compatibility with PyTorch: on Mac OS X it works with PyTorch 1.5.1, and newer versions have known issues.
- For other limitations (such as specific platform or version details), please refer to the official documentation.