Level 1: Threading
Level 1 provides thread pool optimization for I/O-bound workloads.
Overview
| Aspect | Value |
|---|---|
| Overhead | ~50μs per call |
| Memory | ~5MB |
| Best For | I/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 Type | Benefit |
|---|---|
| HTTP requests | High |
| File I/O | High |
| Database queries | High |
| Network operations | High |
Example: HTTP Fetching
import epochlyimport 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 concurrentlyurls = [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.