Skip to content

Commit 5b4a728

Browse files
committed
Update changelog and docs for ASGI NIF optimizations
- Add ASGI NIF optimizations to 1.8.0 changelog - Document all 6 optimizations with expected improvements - Update web-frameworks.md with optimization details table
1 parent 9a3faca commit 5b4a728

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
### Added
66

7+
- **ASGI NIF Optimizations** - Six optimizations for high-performance ASGI request handling
8+
- **Direct Response Tuple Extraction** - Extract `(status, headers, body)` directly without generic conversion
9+
- **Pre-Interned Header Names** - 16 common HTTP headers cached as PyBytes objects
10+
- **Cached Status Code Integers** - 14 common HTTP status codes cached as PyLong objects
11+
- **Zero-Copy Request Body** - Large bodies (≥1KB) use buffer protocol for zero-copy access
12+
- **Scope Template Caching** - Thread-local cache of 64 scope templates keyed by path hash
13+
- **Lazy Header Conversion** - Headers converted on-demand for requests with ≥4 headers
14+
715
- **erlang_asyncio Module** - Asyncio-compatible primitives using Erlang's native scheduler
816
- `erlang_asyncio.sleep(delay, result=None)` - Sleep using Erlang's `erlang:send_after/3`
917
- `erlang_asyncio.run(coro)` - Run coroutine with ErlangEventLoop
@@ -40,6 +48,13 @@
4048

4149
### Performance
4250

51+
- **ASGI marshalling optimizations** - 40-60% improvement for typical ASGI workloads
52+
- Direct response extraction: 5-10% improvement
53+
- Pre-interned headers: 3-5% improvement
54+
- Cached status codes: 1-2% improvement
55+
- Zero-copy body buffers: 10-15% for large bodies (≥1KB)
56+
- Scope template caching: 15-20% for repeated paths
57+
- Lazy header conversion: 5-10% for apps accessing few headers
4358
- **Eliminates event loop overhead** for sleep operations (~0.5-1ms saved per call)
4459
- **Sub-millisecond timer precision** via BEAM scheduler (vs 10ms asyncio polling)
4560
- **Zero CPU when idle** - event-driven, no polling

docs/web-frameworks.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ Compared to generic `py:call()`-based handling:
2222
| Direct NIF | +25-30% | +25-30% |
2323
| **Total** | ~60-80% | ~60-80% |
2424

25+
#### ASGI NIF Optimizations
26+
27+
The ASGI module includes six additional NIF-level optimizations:
28+
29+
| Optimization | Improvement | Description |
30+
|--------------|-------------|-------------|
31+
| Direct Response Extraction | 5-10% | Extract `(status, headers, body)` directly to Erlang terms |
32+
| Pre-Interned Headers | 3-5% | 16 common HTTP headers cached as PyBytes |
33+
| Cached Status Codes | 1-2% | 14 common status codes cached as PyLong |
34+
| Zero-Copy Body | 10-15% | Large bodies (≥1KB) use buffer protocol |
35+
| Scope Template Caching | 15-20% | Thread-local cache of 64 scope templates |
36+
| Lazy Header Conversion | 5-10% | Headers converted on-demand (≥4 headers) |
37+
38+
**Total expected improvement: 40-60%** for typical ASGI workloads on top of the base optimizations.
39+
40+
These optimizations are automatic and require no code changes.
41+
2542
## ASGI Support
2643

2744
### Basic Usage

0 commit comments

Comments
 (0)