Skip to content

Conversation

@shindonghwi
Copy link

@shindonghwi shindonghwi commented Dec 19, 2025

`Headers._list` stores tuples as `(raw_key, lowercase_key, value)`.

In `get_list()` and `delitem()`, calling `.lower()` on `item_key` is redundant since it's already lowercase.

# Before
if item_key.lower() == get_header_key

# After  
if item_key == get_header_key

Benchmark

# 10 headers, 100k iterations
_list = [(key, key.lower(), b'value') for key in headers]
get_header_key = b'x-header-5'

# Original
[v for _, k, v in _list if k.lower() == get_header_key]  # 0.0647s

# Fixed
[v for _, k, v in _list if k == get_header_key]          # 0.0437s

Result: 32.5% faster (1.48x speedup)

The _list stores (raw_key, lowercase_key, value) tuples, so the
second element is already lowercase. Calling .lower() on it again
is unnecessary and wastes CPU cycles.

Benchmark shows ~1.6x speedup for header lookups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant