Skip to main content

Adaptive Code Flow Optimizer for Python

Project description

Adaptive Code Flow Optimizer (ACFO)

The Adaptive Code Flow Optimizer (ACFO) is a Python framework that dynamically optimizes the execution order of function calls, prioritizing high-cost operations while respecting dependencies. By leveraging runtime profiling and a Control Flow Graph (CFG), ACFO enhances performance in applications like data pipelines, web servers, and IoT devices without requiring code modifications.

Key Features

  • Dynamic Optimization: Reorders function calls based on a heuristic ( h(v) = \text{frequency} \cdot \text{cost} ).
  • Dependency-Aware: Ensures correct execution order using a CFG parsed with Python's ast module.
  • Transparent: Integrates seamlessly with existing Python code.
  • Open-Source: Licensed under MIT, welcoming contributions.

Why Use ACFO?

  • Performance Gains: Reduces execution time by prioritizing costly functions.
  • Ease of Use: No need to rewrite code; ACFO profiles and optimizes automatically.
  • Versatility: Applicable to scientific computing, web development, and embedded systems.

Installation

  1. Clone the repository:
    git clone https://github.com/your-username/acfo.git
    cd acfo
    
  2. Create a virtual environment:
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies (none required currently):
    pip install -r requirements.txt
    
  4. Install ACFO as a package (optional):
    pip install .
    

Quick Start

Optimize a simple program with two functions:

from acfo import ACFO

def a():
    time.sleep(0.1)  # Simulates a costly task
    return "A"

def b():
    time.sleep(0.05)  # Simulates a lightweight task
    return "B"

acfo = ACFO()
acfo.parse_code("""
def a():
    b()
def b():
    pass
""")
functions = {"a": a, "b": b}
calls = []
for _ in range(10):
    acfo.monitor_execution("a", a)
    acfo.monitor_execution("b", b)
    calls.append("a")
    calls.append("b")
print("Initial Calls:", calls)
calls = []
acfo.execute_optimized(functions, calls, 20)
print("Optimized Calls:", calls)

Expected Output:

Initial Calls: ['a', 'b', 'a', 'b', ..., 'a', 'b']
Optimized Calls: ['a', 'b', 'a', 'b', ..., 'a', 'b']

Use Cases

  • Data Pipelines: Optimize workflows like read_data -> transform_data -> write_data (see examples/data_pipeline.py).
  • Web Servers: Reduce latency in Flask/Django by reordering middleware or route handlers.
  • IoT Devices: Minimize execution time in resource-constrained environments.

Project Structure

Adaptive-Code-Flow-Optimizer/
├── acfo/               # Core module
│   ├── __init__.py
│   ├── acfo.py
├── examples/           # Example scripts
│   ├── simple_dependency.py
│   ├── data_pipeline.py
├── tests/              # Unit tests
│   ├── test_acfo.py
├── docs/               # Detailed documentation
│   ├── architecture.md
│   ├── contributing.md
├── .gitignore
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py

Contributing

We welcome contributions! Please read contributing.md for guidelines on reporting issues, submitting pull requests, and coding standards.

Documentation

License

MIT License

Contact


ACFO: Optimize your Python code dynamically, effortlessly, and intelligently.

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

acfo-1.0.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

acfo-1.0.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file acfo-1.0.0.tar.gz.

File metadata

  • Download URL: acfo-1.0.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for acfo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0744081cebd0c63fd545bc9be8d82f0eead2457c36ed681eeebd3f5c7cd26acc
MD5 e4da02df4f764e8e067117a111ff5381
BLAKE2b-256 bee7f98fafa9b6854c79dac020f006397b7a163d5f8930ac6d15aac093dc4ba7

See more details on using hashes here.

File details

Details for the file acfo-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: acfo-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for acfo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed9e6d3190a1318f6413c9b4610d161cc923c039eea25e50494eb7f5fffa4225
MD5 c64017605c4e905ea4a1c68ec87ba14c
BLAKE2b-256 41930de15b4134171fbfd16ec0c68d40b58a1ac2ddf52275d00f9213c3a240a1

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