Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize header name handling in Grpc::map_response #1359

Merged

Conversation

srijs
Copy link
Contributor

@srijs srijs commented Apr 16, 2023

Avoid parsing reserved header names on every call to MetadataMap::into_sanitized_headers as well as in Status::to_http. More explanation below. The change should be relatively straight forward and low-complexity, but let me know if you'd like to see an isolated benchmark for this regardless!

Motivation

The MetadataMap::into_sanitized_headers function is called for every response transitively through Grpc::map_response and Response::into_http.

The way that it currently sanitizes headers by removing the reserved GRPC headers involves calling HeaderMap::remove with a &str key, which results in the string key being parsed into a header name at runtime for every one of the reserved headers (see the call here).

This makes it show up on my profiles in the single-digit percentage range, which seemed worthwhile improving to me, especially considering the low complexity of the change.

A similar situation exists in Status::to_http where the GRPC status header names are being parsed at runtime when inserted into the header map.

Solution

The solution implemented is to parse the reserved headers at compile time using the const function HeaderName::from_static. This eliminates any runtime overhead of parsing the reserved header names.

@srijs srijs changed the title optimize MetadataMap::into_sanitized_headers optimize header name handling in Response::into_http Apr 16, 2023
@srijs srijs changed the title optimize header name handling in Response::into_http optimize header name handling in Grpc::map_response Apr 16, 2023
@srijs srijs force-pushed the optimize-response-into-http-header-handling branch from 7bf69be to 2c83f31 Compare April 16, 2023 13:31
@srijs
Copy link
Contributor Author

srijs commented May 1, 2023

@LucioFranco this should be a relatively simple chance, any indication as to whether you'd be able to merge it or have any feedback would be appreciated, thanks!

@tottoto tottoto added this pull request to the merge queue Sep 20, 2024
Merged via the queue into hyperium:master with commit a09d453 Sep 20, 2024
17 checks passed
@tottoto
Copy link
Collaborator

tottoto commented Sep 20, 2024

Thank you!

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.

2 participants