Skip to main content

Intelligent performance bottleneck detection for Python developers

Project description

py-performance-hints

Python 3.8+ Development Status

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!

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_performance_hints-0.1.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_performance_hints-0.1.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

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

Hashes for py_performance_hints-0.1.0.tar.gz
Algorithm Hash digest
SHA256 491fd2b5eef096a8a75f9c532f99c831da15d43910bbb2f8eecf0a1b112c1315
MD5 e4a2592a2d25d3d8a68c59962b6954db
BLAKE2b-256 e140b012c435f38caf1a106a409508d1f0c5ba5031170dd624ab6b7f410d2f32

See more details on using hashes here.

File details

Details for the file py_performance_hints-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_performance_hints-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09d10db250a0b0dc679d1a1e7e8d7742e027c3a7f8d5bf471376a6b56f82dd49
MD5 87ae2ebced134761ea3f46ce1b58af1a
BLAKE2b-256 cd4c263519ddbbfd455312c4d52cb4c8d79611f7a6a1bccb90a6df562661450f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page