Bug 1794598 - Optimize string allocation in ClassOfService::ToString() r=necko-reviewers,valentin

We want to save heap allocations in this important codepath.

Differential Revision: https://phabricator.services.mozilla.com/D159626
This commit is contained in:
Andrew Creskey
2022-10-24 16:28:15 +00:00
parent 8c375fa746
commit 9635acd94b
3 changed files with 14 additions and 12 deletions

View File

@@ -1231,14 +1231,16 @@ HttpChannelParent::OnStartRequest(nsIRequest* aRequest) {
if (!args.timing().domainLookupEnd().IsNull() &&
!args.timing().connectStart().IsNull()) {
nsCString protocolVersion;
nsAutoCString protocolVersion;
mChannel->GetProtocolVersion(protocolVersion);
uint32_t classOfServiceFlags = 0;
mChannel->GetClassFlags(&classOfServiceFlags);
nsAutoCString cosString;
ClassOfService::ToString(classOfServiceFlags, cosString);
nsAutoCString key(
nsPrintfCString("%s_%s", protocolVersion.get(), cosString.get()));
Telemetry::AccumulateTimeDelta(
Telemetry::NETWORK_DNS_END_TO_CONNECT_START_EXP_MS,
protocolVersion + "_"_ns +
ClassOfService::ToString(classOfServiceFlags),
Telemetry::NETWORK_DNS_END_TO_CONNECT_START_EXP_MS, key,
args.timing().domainLookupEnd(), args.timing().connectStart());
}