Skip to content

Commit

Permalink
golang: optimize copyHeaderMapToGo: reduce memory copy. (envoyproxy#3…
Browse files Browse the repository at this point in the history
…6023)

Commit Message:
Additional Description:
In my local benchmark(requires some hack for benchmark), it makes header
map init faster 10%+.
from 2656ns to 2269ns for per header map init.

Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional [API
Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):]

Signed-off-by: doujiang24 <[email protected]>
  • Loading branch information
doujiang24 authored Sep 9, 2024
1 parent 787bba3 commit 3537377
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contrib/golang/filters/http/source/golang_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ CAPIStatus Filter::getHeader(ProcessorState& state, absl::string_view key, uint6
void copyHeaderMapToGo(Http::HeaderMap& m, GoString* go_strs, char* go_buf) {
auto i = 0;
m.iterate([&i, &go_strs, &go_buf](const Http::HeaderEntry& header) -> Http::HeaderMap::Iterate {
auto key = std::string(header.key().getStringView());
auto value = std::string(header.value().getStringView());
// It's safe to use StringView here, since we will copy them into Golang.
auto key = header.key().getStringView();
auto value = header.value().getStringView();

auto len = key.length();
// go_strs is the heap memory of go, and the length is twice the number of headers. So range it
Expand Down

0 comments on commit 3537377

Please sign in to comment.