Bug 1344152 - Determine how many scripts are in "Latin 1";f?hsivonen
We believe that we can make JS parsing much faster for script using
unicode chars in [0x00, 0xFF[. This patch attempts to determine:
- how common such scripts are;
- how long it takes to find out that we are faced with such a script.
Since finding out if a script is within [0x00, 0xFF[ can take time,
this patch limits collection to sample randomly once every 10k loads.
MozReview-Commit-ID: EOiT73SaPeE
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -71,16 +71,19 @@ static LazyLogModule gScriptLoaderLog("S
MOZ_LOG(gScriptLoaderLog, mozilla::LogLevel::Verbose, args)
#define LOG(args) \
MOZ_LOG(gScriptLoaderLog, mozilla::LogLevel::Debug, args)
#define LOG_WARN(args) \
MOZ_LOG(gScriptLoaderLog, mozilla::LogLevel::Warning, args)
#define LOG_ERROR(args) \
MOZ_LOG(gScriptLoaderLog, mozilla::LogLevel::Error, args)
+// Measuring DOM_SCRIPT_SRC_UNICODE_SUBSET can be expensive, so we only do it
+// randomly, on average once every SAMPLE_DOM_SCRIPT_SRC_UNICODE_SUBSET times.
+#define SAMPLE_DOM_SCRIPT_SRC_UNICODE_SUBSET 10000
void
ImplCycleCollectionUnlink(nsScriptLoadRequestList& aField);
void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
nsScriptLoadRequestList& aField,
const char* aName,
@@ -3086,12 +3089,30 @@ nsScriptLoadHandler::OnStreamComplete(ns
/* aEndOfStream = */ true);
// If SRI is required for this load, appending new bytes to the hash.
if (mSRIDataVerifier && NS_SUCCEEDED(mSRIStatus)) {
mSRIStatus = mSRIDataVerifier->Update(aDataLength, aData);
}
}
+ // Update Telemetry.
+ // As this is expensive, we only do it on a randomized sample of scripts.
+ if (Telemetry::CanRecordExtended() && (rand() % SAMPLE_DOM_SCRIPT_SRC_UNICODE_SUBSET == 0)) {
+ const mozilla::TimeStamp start = mozilla::TimeStamp::Now();
+ bool isSingleByte = true;
+ for (char16_t c: mRequest->mScriptText) {
+ if (c < 0xFF) {
+ isSingleByte = false;
+ break;
+ }
+ }
+ const mozilla::TimeStamp stop = mozilla::TimeStamp::Now();
+ Telemetry::Accumulate(Telemetry::DOM_SCRIPT_SRC_UNICODE_SUBSET,
+ isSingleByte ? 1 /* "Latin 1" */: 0 /* Anything else */);
+ Telemetry::Accumulate(Telemetry::DOM_SCRIPT_SRC_UNICODE_SUBSET_DURATION_MS,
+ (stop - start).ToMilliseconds());
+ }
+
// we have to mediate and use mRequest.
return mScriptLoader->OnStreamComplete(aLoader, mRequest, aStatus, mSRIStatus,
mSRIDataVerifier);
}
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -10543,16 +10543,33 @@
"DOM_SCRIPT_SRC_ENCODING": {
"alert_emails": ["dteller@mozilla.com"],
"expires_in_version": "never",
"kind": "count",
"keyed": true,
"bug_numbers": [1344152],
"description": "Encoding used in a <script src>."
},
+ "DOM_SCRIPT_SRC_UNICODE_SUBSET": {
+ "alert_emails": ["dteller@mozilla.com"],
+ "expires_in_version": "never",
+ "kind": "enumerated",
+ "bug_numbers": [1344152],
+ "n_values": 10,
+ "description": "Actual subset of Unicode used in a <script src>. Current values are 0 (unspecified), 1 (all chars are < 0xff)."
+ },
+ "DOM_SCRIPT_SRC_UNICODE_SUBSET_DURATION_MS": {
+ "alert_emails": ["dteller@mozilla.com"],
+ "expires_in_version": "never",
+ "kind": "exponential",
+ "bug_numbers": [1344152],
+ "n_buckets": 10,
+ "high": 10000,
+ "description": "Time spent collecting the information to find out the value of DOM_SCRIPT_SRC_UNICODE_SUBSET, in ms."
+ },
"WEB_NOTIFICATION_REQUEST_PERMISSION_CALLBACK": {
"alert_emails": ["push@mozilla.com"],
"expires_in_version": "55",
"bug_numbers": [1241278],
"kind": "boolean",
"description": "Usage of the deprecated Notification.requestPermission() callback argument"
},
"VIDEO_FASTSEEK_USED": {