Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/cachekey/cachekey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ getCanonicalUrl(TSMBuffer buf, TSMLoc url, bool canonicalPrefix, bool provideDef
} else {
if (provideDefaultKey) {
/* return the key default - results in '/host/port' */
canonicalUrl.assign("/").append(host).append("/").append(port);
canonicalUrl.assign(1, '/').append(host).append("/").append(port);
} else {
/* return regex input string - results in 'host:port' (use-case kept for compatibility reasons) */
canonicalUrl.assign(host).append(":").append(port);
Expand Down
9 changes: 6 additions & 3 deletions plugins/experimental/rate_limit/limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,15 @@ template <class T> class RateLimiter
memset(_metrics, 0, sizeof(_metrics));

std::string metric_prefix = prefix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you use the std::string::reserve() member function for these so there will be only one heap allocation?

Copy link
Contributor Author

@traeak traeak Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you use the std::string::reserve() member function for these so there will be only one heap allocation?

This function is "initializeMetrics" which is only called during plugin initialization. And there's more logic below in the function for building this metric_prefix string. You might save one heap allocation with a reserve for something not in a performance sensitive place with probably too high a maintenance cost.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK it looked like a performance PR to me. What are the ambiguities in the current code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it's due to the std::string/std::string_view handling (circular dependency hell) where the compiler might get confused trying to figure out how to deal with the first argument in the following (for example):

result += "/" + somestringfunc();

metric_prefix.append("." + std::string(types[type]));
metric_prefix.push_back('.');
metric_prefix.append(types[type]);

if (!tag.empty()) {
metric_prefix.append("." + tag);
metric_prefix.push_back('.');
metric_prefix.append(tag);
} else if (!name().empty()) {
metric_prefix.append("." + name());
metric_prefix.push_back('.');
metric_prefix.append(name());
}

for (int i = 0; i < RATE_LIMITER_METRIC_MAX; i++) {
Expand Down
3 changes: 2 additions & 1 deletion plugins/experimental/rate_limit/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ getDescriptionFromUrl(const char *url)
// only append the port when it is non-standard
if (!(strncmp(s, TS_URL_SCHEME_HTTP, scheme_len) == 0 && port == 80) &&
!(strncmp(s, TS_URL_SCHEME_HTTPS, scheme_len) == 0 && port == 443)) {
description.append(":" + std::to_string(port));
description.push_back(':');
description.append(std::to_string(port));
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/prefetch/evaluate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ sub(StringView const lhs, StringView const rhs)

// if result would have been negative.
if (borrow) {
result = "0";
result = std::string{"0"};
}

return result;
Expand Down
6 changes: 3 additions & 3 deletions plugins/traffic_dump/json_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ namespace traffic_dump
std::string
json_entry(std::string_view name, std::string_view value)
{
return "\"" + escape_json(name) + "\":\"" + escape_json(value) + "\"";
return std::string{"\""} + escape_json(name) + "\":\"" + escape_json(value) + "\"";
}

std::string
json_entry(std::string_view name, char const *value, int64_t size)
{
return "\"" + escape_json(name) + "\":\"" + escape_json(value, size) + "\"";
return std::string{"\""} + escape_json(name) + "\":\"" + escape_json(value, size) + "\"";
}

std::string
json_entry_array(std::string_view name, std::string_view value)
{
return "[\"" + escape_json(name) + "\",\"" + escape_json(value) + "\"]";
return std::string{"[\""} + escape_json(name) + "\",\"" + escape_json(value) + "\"]";
}

std::string
Expand Down
4 changes: 2 additions & 2 deletions plugins/traffic_dump/session_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ SessionData::write_transaction_to_disk(std::string_view content)
// Prepend a comma.
std::string with_comma;
with_comma.reserve(content.size() + 1);
with_comma.insert(0, ",");
with_comma.insert(1, content);
with_comma.push_back(',');
with_comma.append(content);
result = write_to_disk_no_lock(with_comma);
} else {
result = write_to_disk_no_lock(content);
Expand Down
2 changes: 1 addition & 1 deletion plugins/traffic_dump/transaction_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ TransactionData::write_message_node_no_content(TSMBuffer &buffer, TSMLoc &hdr_lo
// 3. "method":(string)
cp = TSHttpHdrMethodGet(buffer, hdr_loc, &len);
Dbg(dbg_ctl, "write_message_node(): found method %.*s ", len, cp);
result += "," + traffic_dump::json_entry("method", cp, len);
result += ',' + traffic_dump::json_entry("method", cp, len);

// 4. "url"
cp = TSUrlHostGet(buffer, url_loc, &len);
Expand Down