Skip to content

Commit 1f4b223

Browse files
committed
skip resources
1 parent e97e272 commit 1f4b223

2 files changed

Lines changed: 60 additions & 46 deletions

File tree

JetStreamDriver.js

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function getBoolParam(urlParams, key, defaultValue=false) {
5757
if (!urlParams.has(key))
5858
return defaultValue;
5959
const rawValue = urlParams.get(key).toLowerCase()
60-
return (rawValue !== "false" && rawValue !== "0")
60+
return !(rawValue === "false" || rawValue === "0")
6161
}
6262

6363
if (typeof(URLSearchParams) !== "undefined") {
@@ -70,9 +70,12 @@ if (typeof(URLSearchParams) !== "undefined") {
7070
customTestList = urlParameters.getAll("test");
7171
globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount");
7272
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
73-
globalThis.prefetchResources = getBoolParam(urlParameters, "prefetchResources", true)
73+
globalThis.prefetchResources = getBoolParam(urlParameters, "prefetchResources", true);
7474
}
7575

76+
if (!globalThis.prefetchResources)
77+
console.warn("Disabling resource prefetching!", globalThis.prefetchResources)
78+
7679
// Used for the promise representing the current benchmark run.
7780
this.currentResolve = null;
7881
this.currentReject = null;
@@ -199,54 +202,56 @@ function uiFriendlyDuration(time)
199202
return result;
200203
}
201204

202-
const fileLoader = (function() {
203-
class Loader {
204-
constructor() {
205-
this.requests = new Map;
205+
class FileLoader {
206+
constructor() {
207+
this.requests = new Map;
208+
}
209+
210+
async _loadInternal(url) {
211+
if (!isInBrowser) {
212+
if (!globalThis.prefetchResources)
213+
return Promise.resolve(`load("${url}");`);
214+
return Promise.resolve(readFile(url));
206215
}
207216

208-
async _loadInternal(url) {
209-
if (!isInBrowser) {
210-
if (!globalThis.prefetchResources)
211-
return Promise.resolve(`load("${url}");`);
212-
return Promise.resolve(readFile(url));
213-
}
217+
if (!globalThis.prefetchResources)
218+
return Promise.resolve(`<script src="${url}"></script>"`);
214219

215-
let response;
216-
const tries = 3;
217-
while (tries--) {
218-
let hasError = false;
219-
try {
220-
response = await fetch(url);
221-
} catch (e) {
222-
hasError = true;
223-
}
224-
if (!hasError && response.ok)
225-
break;
226-
if (tries)
227-
continue;
228-
globalThis.allIsGood = false;
229-
throw new Error("Fetch failed");
220+
let response;
221+
const tries = 3;
222+
while (tries--) {
223+
let hasError = false;
224+
try {
225+
response = await fetch(url);
226+
} catch (e) {
227+
hasError = true;
230228
}
231-
if (url.indexOf(".js") !== -1)
232-
return response.text();
233-
else if (url.indexOf(".wasm") !== -1)
234-
return response.arrayBuffer();
235-
236-
throw new Error("should not be reached!");
229+
if (!hasError && response.ok)
230+
break;
231+
if (tries)
232+
continue;
233+
globalThis.allIsGood = false;
234+
throw new Error("Fetch failed");
237235
}
236+
if (url.indexOf(".js") !== -1)
237+
return response.text();
238+
else if (url.indexOf(".wasm") !== -1)
239+
return response.arrayBuffer();
238240

239-
async load(url) {
240-
if (this.requests.has(url))
241-
return this.requests.get(url);
241+
throw new Error("should not be reached!");
242+
}
242243

243-
const promise = this._loadInternal(url);
244-
this.requests.set(url, promise);
245-
return promise;
246-
}
244+
async load(url) {
245+
if (this.requests.has(url))
246+
return this.requests.get(url);
247+
248+
const promise = this._loadInternal(url);
249+
this.requests.set(url, promise);
250+
return promise;
247251
}
248-
return new Loader;
249-
})();
252+
}
253+
254+
const fileLoader = new FileLoader();
250255

251256
class Driver {
252257
constructor() {
@@ -295,7 +300,7 @@ class Driver {
295300
benchmark.updateUIAfterRun();
296301
console.log(benchmark.name)
297302

298-
if (isInBrowser) {
303+
if (isInBrowser && globalThis.prefetchResources) {
299304
const cache = JetStream.blobDataCache;
300305
for (const file of benchmark.plan.files) {
301306
const blobData = cache[file];
@@ -803,8 +808,12 @@ class Benchmark {
803808
addScript(text);
804809
} else {
805810
const cache = JetStream.blobDataCache;
806-
for (const file of this.plan.files)
807-
addScriptWithURL(cache[file].blobURL);
811+
for (const file of this.plan.files) {
812+
if (globalThis.prefetchResources)
813+
addScriptWithURL(cache[file].blobURL);
814+
else
815+
addScriptWithURL(file);
816+
}
808817
}
809818

810819
const promise = new Promise((resolve, reject) => {
@@ -857,6 +866,11 @@ class Benchmark {
857866
}
858867

859868
async doLoadBlob(resource) {
869+
const blobData = JetStream.blobDataCache[resource];
870+
if (!globalThis.prefetchResources) {
871+
blobData.blobURL = resource;
872+
return blobData;
873+
}
860874
let response;
861875
let tries = 3;
862876
while (tries--) {
@@ -873,7 +887,6 @@ class Benchmark {
873887
throw new Error("Fetch failed");
874888
}
875889
const blob = await response.blob();
876-
const blobData = JetStream.blobDataCache[resource];
877890
blobData.blob = blob;
878891
blobData.blobURL = URL.createObjectURL(blob);
879892
return blobData;

cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ globalThis.prefetchResources = true;
2727
const isInBrowser = false;
2828
console = {
2929
log: globalThis?.console?.log ?? print,
30+
warn: globalThis?.console?.warn ?? print,
3031
error: globalThis?.console?.error ?? print,
3132
}
3233

0 commit comments

Comments
 (0)