Avoid redundant normalization of parsed wire headers - #207
Open
Johnny-Kao wants to merge 2 commits into
Open
Johnny-Kao wants to merge 2 commits into
Johnny-Kao wants to merge 2 commits into
Conversation
Author
|
First time contributing to h11 — this was a really interesting codebase to work on. The implementation is impressively solid, especially around the protocol and validation boundaries. Happy to adjust anything if needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Headersdirectly while decoding header lines from the wireWhy
The receive path currently validates each wire header line, materializes a temporary
(name, value)list, and then passes that list throughnormalize_and_validate(..., _parsed=True), which walks the headers again to lowercase names, normalize Content-Length / Transfer-Encoding, and construct the internal three-tuple representation.This change keeps the existing trust boundary and protocol checks, but removes the intermediate pair representation and redundant traversal. The public
Request/Responseconstruction path is unchanged.Correctness / safety
The parser still validates every header line before applying Content-Length / Transfer-Encoding semantic checks. A regression test locks in that ordering.
Local validation:
79 passedgit diff --check: passThe change does not alter obs-fold behavior; it is independent of #198.
Performance
Interleaved A/B measurements in the same Python process were used to reduce scheduler/frequency noise.
On the local Apple Silicon environment:
27.45 us->26.54 us)Connection.next_event()path: ~5.6% lower median timeThe performance claim is intentionally limited to these parsing/benchmark workloads rather than h11 overall.