scalene  by plasma-umass

Python profiler with AI-powered optimization proposals

created 5 years ago
12,822 stars

Top 3.9% on sourcepulse

GitHubView on GitHub
Project Summary

Scalene is a high-performance Python profiler designed to identify performance bottlenecks across CPU, GPU, and memory usage. It offers unparalleled detail and speed compared to many existing profilers, with the unique addition of AI-powered optimization suggestions. This tool is invaluable for developers seeking to optimize Python applications, from individual functions to entire codebases.

How It Works

Scalene employs a sampling-based approach rather than instrumentation, resulting in significantly lower overhead (typically 10-20%). It meticulously separates time spent in Python code from time spent in native libraries and system calls, allowing developers to focus optimization efforts effectively. For memory profiling, it utilizes a specialized memory allocator to track usage per line and identify potential leaks or excessive copying.

Quick Start & Requirements

  • Install: pip install -U scalene or conda install -c conda-forge scalene
  • Run: scalene your_prog.py
  • Prerequisites: Python 3.x. GPU profiling is limited to NVIDIA systems. Windows users should note that memory and copy profiling are not supported.
  • Resources: Setup is minimal; profiling overhead is generally low.
  • Docs: Scalene Demo Notebook

Highlighted Details

  • AI-powered optimization suggestions using GPT-4 (requires OpenAI API key).
  • Detailed breakdown of CPU time (Python vs. native vs. system) and memory allocation.
  • GPU profiling support for NVIDIA hardware.
  • Line-level profiling for both CPU and memory, with leak detection.

Maintenance & Community

  • Project led by Emery Berger, Sam Stern, and Juan Altmayer Pizzorno.
  • Community support available via Slack.
  • Active development, with a paper on its internals winning an award at OSDI 2023.

Licensing & Compatibility

  • License: Not explicitly stated in the README, but commonly associated with permissive licenses for research projects. Further clarification may be needed for commercial use.
  • Compatibility: Works with standard Python, Pytest, Django (with --noreload), and gevent (with monkey patching). PyTorch compatibility on Mac may require specific versions due to known issues.

Limitations & Caveats

The Windows version has limitations, excluding memory and copy profiling. Newer PyTorch versions on macOS may experience compatibility issues. AI suggestions require an external API key and incur costs.

Health Check
Last commit

3 weeks ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
1
Star History
230 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.