Skip to content

Performance optimizations for parsers#148

Open
benoitc wants to merge 3 commits into
ninenines:masterfrom
benoitc:feature/perf-improvements
Open

Performance optimizations for parsers#148
benoitc wants to merge 3 commits into
ninenines:masterfrom
benoitc:feature/perf-improvements

Conversation

@benoitc

@benoitc benoitc commented Feb 20, 2026

Copy link
Copy Markdown

Summary

  • Optimize header parsing in cow_http1 with skip/len pattern
  • Add map indices for O(1) lookup in HPACK/QPACK dynamic tables

Results

Module Change Improvement
cow_http1 skip/len parsing ~2x faster
cow_hpack map lookup O(n) → O(1)
cow_qpack map lookup O(n) → O(1)

All tests pass.

Use skip/len tracking instead of byte-by-byte binary accumulation
in parse_hd_value. This avoids O(n²) allocation overhead.

Key changes:
- Track original binary + skip position + length
- Add 4-byte chunking for faster scanning
- Separate fast path for single-segment vs folded headers
- Use binary:part/3 only at boundaries

Benchmark shows ~2.1x speedup for typical header blocks.
Add map-based indices for O(1) header lookup during encoding.
Previously, finding a header in the dynamic table required O(n)
linear scan. Now uses maps with sequence numbers.

Key changes:
- Add dyn_field_idx and dyn_name_idx maps to state record
- Store sequence numbers; compute actual index via maps:size
- Insert without eviction is O(1) (no map shifting needed)
- Rebuild maps only on eviction (less frequent operation)
- Add bench/0 for performance testing

Lookup formula: index = 62 + (count - 1 - seq)
Benchmark: 0.036 us/lookup with 50 dynamic entries.
Add map-based indices for O(1) header lookup during encoding,
similar to the HPACK optimization.

Key changes:
- Add dyn_field_idx and dyn_name_idx maps to state record
- Store absolute indices (which never change in QPACK)
- Insert without eviction is O(1)
- Rebuild maps only on eviction
- Add bench/0 for performance testing

Benchmark: 0.037 us/lookup with 50 dynamic entries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant