Optimize memory usage by using string_view for filter config name#44962
Optimize memory usage by using string_view for filter config name#44962etruong42 wants to merge 3 commits into
Conversation
e476767 to
2936881
Compare
By using absl::string_view, we avoid a string copy per filter instantiation which happens twice if there is both encoder and decoder filters and limit the filter name memory overhead to a pointer and a length (instead of a string copy). This should be safe since filter configuration names are owned by FilterConfigProvider which are owned by the HttpConnectionManager, and the HttpConnectionManager is kept alive until all existing connections and streams using it have finished. Signed-off-by: Ethan Truong <ethantruong@google.com>
2936881 to
c2641b7
Compare
|
/assign yanjunxiang-google |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request optimizes filter configuration handling by replacing std::string with absl::string_view in FilterContext and LocalReplyOwnerObject to reduce unnecessary string copies. In tests, a filter_names_ container was introduced to provide stable storage for these views. Review feedback suggests further optimizing LocalReplyOwnerObject by updating its member variable to absl::string_view to avoid a copy during initialization. Additionally, it is recommended to use std::list instead of std::vector for filter_names_ in tests to guarantee pointer stability and eliminate the risk of use-after-free errors caused by vector reallocations, which would also remove the need for manual reserve() calls.
Signed-off-by: Ethan Truong <ethantruong@google.com>
3b52968 to
603b6ca
Compare
By using absl::string_view, we avoid a string copy per filter instantiation which happens twice if there is both encoder and decoder filters and limit the filter name memory overhead to a pointer and a length (instead of a string copy).
This should be safe since filter configuration names are owned by FilterConfigProvider which are owned by the HttpConnectionManager, and the HttpConnectionManager is kept alive until all existing connections and streams using it have finished.
Commit Message:
Additional Description:
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:]