Intelligent performance bottleneck detection for Python developers
Project description
py-performance-hints
Intelligent performance bottleneck detection for Python developers. Get real-time hints about performance anti-patterns in your code during development.
๐ Quick Start
Installation
pip install py-performance-hints
Basic Usage
from performance_hints import monitor_performance
@monitor_performance
def slow_function():
import time
time.sleep(0.15) # This will trigger a warning
return "completed"
slow_function()
Output:
[14:32:15] Performance hints for slow_function()
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๏ธ Slow execution: 151.2ms
Function 'slow_function' took 151.2ms to execute (threshold: 100.0ms)
๐ก Suggestion: Check for inefficient loops or data structures โข Consider optimizing algorithm complexity
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Total execution time: 151.2ms
๐ฏ Features (Phase 1)
- ๐ Timing Detection: Automatically detects functions that exceed time thresholds
- ๐จ Beautiful Console Output: Colored, formatted output with clear suggestions
- โ๏ธ Configurable: Customize thresholds and detection patterns
- ๐ชถ Lightweight: Minimal overhead (< 5% performance impact)
- ๐ Smart Suggestions: Context-aware performance improvement tips
๐ Usage Examples
Custom Threshold
@monitor_performance(threshold_ms=50)
def critical_function():
# Will warn if execution takes > 50ms
pass
Global Configuration
from performance_hints import configure
configure(
threshold_ms=75,
detect_patterns=['timing'],
report_format='console'
)
Selective Monitoring
# Only monitor in development
@monitor_performance(enabled=DEBUG)
def production_function():
pass
# Disable for specific functions
@monitor_performance(enabled=False)
def unmonitored_function():
pass
โ๏ธ Configuration
Environment Variables
export PERFORMANCE_HINTS_ENABLED=true
export PERFORMANCE_HINTS_THRESHOLD_MS=100
export PERFORMANCE_HINTS_PATTERNS=timing
export PERFORMANCE_HINTS_FORMAT=console
Programmatic Configuration
from performance_hints import configure
configure(
enabled=True,
threshold_ms=100,
detect_patterns=['timing'],
report_format='console'
)
๐ ๏ธ Development Status
Current Status: Phase 1 (Alpha)
โ Implemented
- Basic timing detection
- Console reporter with colors
- Configuration system
- Decorator interface
๐ง Coming in Phase 2
- N+1 query detection
- Nested loop analysis
- Memory usage monitoring
- JSON output format
- CI/CD integration
๐ฎ Future Phases
- IDE integration
- Performance dashboard
- Machine learning suggestions
๐งช Testing
Run the examples:
cd examples
python basic_usage.py
๐ Requirements
- Python 3.8+
- No external dependencies for core functionality
๐ค Contributing
This project is in early development. Contributions welcome!
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
MIT License - see LICENSE file for details.
๐ Changelog
v0.1.0 (Phase 1 - Alpha)
- Initial release
- Basic timing detection
- Console output
- Configuration system
- Decorator interface
Note: This library is in alpha stage. APIs may change between versions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_performance_hints-0.1.0.tar.gz.
File metadata
- Download URL: py_performance_hints-0.1.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
491fd2b5eef096a8a75f9c532f99c831da15d43910bbb2f8eecf0a1b112c1315
|
|
| MD5 |
e4a2592a2d25d3d8a68c59962b6954db
|
|
| BLAKE2b-256 |
e140b012c435f38caf1a106a409508d1f0c5ba5031170dd624ab6b7f410d2f32
|
File details
Details for the file py_performance_hints-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_performance_hints-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09d10db250a0b0dc679d1a1e7e8d7742e027c3a7f8d5bf471376a6b56f82dd49
|
|
| MD5 |
87ae2ebced134761ea3f46ce1b58af1a
|
|
| BLAKE2b-256 |
cd4c263519ddbbfd455312c4d52cb4c8d79611f7a6a1bccb90a6df562661450f
|