JakeChampion / JakeChampion/trafficserver

[audit][perf] Remap host table lookup constructs a heap-allocating std::string temporary per request

Open
#45 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:perf audit severity:medium
Dominant language
C++
Stars
0
Forks
0
Avg merge
8h 2m
Merged PRs (30d)
21

Description

Severity: medium · Category: performance
Location: src/proxy/http/remap/UrlRewrite.cc:314

What's wrong

URLTable is 'std::unordered_map<std::string, UrlMappingPathIndex >' (include/proxy/http/remap/UrlRewrite.h:63) with the default non-transparent std::hashstd::string, and _tableLookup calls 'h_table->find(request_host)' with a char. Every call materializes a temporary std::string from the lowercased host, which heap-allocates and frees for any hostname longer than the SSO threshold (~15 chars — common for real hostnames). _mappingLookup runs on the request path for every forward remap lookup (UrlRewrite.cc:942), so this is an avoidable malloc/free pair plus copy per proxied request; requests that also consult redirect/reverse tables pay it again.

Evidence
UrlRewrite.cc:314: if (auto it = h_table->find(request_host); it != h_table->end()) {
UrlRewrite.h:63: using URLTable = std::unordered_map<std::string, UrlMappingPathIndex *>;
UrlRewrite.cc:942: url_mapping *mapping = _tableLookup(mappings.hash_lookup, request_url, request_port, request_host_lower, request_host_len);
Suggested fix

Enable C++20 heterogeneous lookup: define a transparent hash/equal (struct with is_transparent operating on std::string_view) for URLTable and pass std::string_view{request_host_lower, request_host_len} to find(); no allocation, and the already-computed length is reused instead of strlen.


Filed from an automated multi-lens codebase audit. Full report: CODEBASE_AUDIT.md / audit-report.html on branch claude/codebase-audit-review-9nw7vz.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with URLTable in include/proxy/http/remap/UrlRewrite.h:63 and _tableLookup in src/proxy/http/remap/UrlRewrite.cc:314, then trace the call from _mappingLookup at line 942. Add the transparent lookup types and use the provided host length without constructing a temporary string. Done means remap lookups preserve behavior without per-request host allocation; run the relevant existing remap tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.