Documentation

Level 1: Threading

Level 1 provides thread pool optimization for I/O-bound workloads.

Overview

AspectValue
Overhead~50μs per call
Memory~5MB
Best ForI/O-bound operations

How It Works

Level 1 uses a managed thread pool to execute I/O operations concurrently.

Enabling Level 1

import epochly
@epochly.optimize(level=1)
def io_function(urls):
return [fetch(url) for url in urls]

When Level 1 Helps

Workload TypeBenefit
HTTP requestsHigh
File I/OHigh
Database queriesHigh
Network operationsHigh

Example: HTTP Fetching

import epochly
import urllib.request
@epochly.optimize(level=1)
def fetch_urls(urls):
results = []
for url in urls:
with urllib.request.urlopen(url) as response:
results.append(response.read())
return results
# 10 URLs fetched concurrently
urls = [f'https://example.com/page/{i}' for i in range(10)]
results = fetch_urls(urls)

When Level 1 Does Not Help

Due to Python's GIL, CPU-bound work does not benefit from threading. Use Level 2 instead.