Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
63 changes: 39 additions & 24 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@ globalThis.dumpJSONResults ??= false;
globalThis.testList ??= undefined;
globalThis.startDelay ??= undefined;
globalThis.shouldReport ??= false;
globalThis.prefetchResources ??= true;

function getIntParam(urlParams, key) {
if (!urlParams.has(key))
return undefined
const rawValue = urlParams.get(key);
const value = parseInt(rawValue);
if (value <= 0)
throw new Error(`Expected positive value for ${key}, but got ${rawValue}`);
return value;
}

function getBoolParam(urlParams, key) {
const rawValue = urlParams.get(key).toLowerCase()
return !(rawValue === "false" || rawValue === "0")
}

function getTestListParam(urlParams, key) {
if (globalThis.testList?.length)
throw new Error(`Overriding previous testList=${globalThis.testList.join()} with ${key} url-parameter.`);
Expand All @@ -73,8 +77,13 @@ if (typeof(URLSearchParams) !== "undefined") {
globalThis.testIterationCount = getIntParam(urlParameters, "iterationCount");
if (urlParameters.has("worstCaseCount"))
globalThis.testWorstCaseCount = getIntParam(urlParameters, "worstCaseCount");
if (urlParameters.has("prefetchResources"))
globalThis.prefetchResources = getBoolParam(urlParameters, "prefetchResources");
}

if (!globalThis.prefetchResources)
console.warn("Disabling resource prefetching!");

// Used for the promise representing the current benchmark run.
this.currentResolve = null;
this.currentReject = null;
Expand Down Expand Up @@ -180,28 +189,29 @@ function uiFriendlyDuration(time) {
// TODO: Cleanup / remove / merge. This is only used for caching loads in the
// non-browser setting. In the browser we use exclusively `loadCache`,
// `loadBlob`, `doLoadBlob`, `prefetchResourcesForBrowser` etc., see below.
const fileLoader = (function() {
class Loader {
constructor() {
this.requests = new Map;
}

// Cache / memoize previously read files, because some workloads
// share common code.
load(url) {
assert(!isInBrowser);
class ShellFileLoader {
constructor() {
this.requests = new Map;
}

if (this.requests.has(url)) {
return this.requests.get(url);
}
// Cache / memoize previously read files, because some workloads
// share common code.
load(url) {
assert(!isInBrowser);
if (!globalThis.prefetchResources)
return `load("${url}");`

const contents = readFile(url);
this.requests.set(url, contents);
return contents;
if (this.requests.has(url)) {
return this.requests.get(url);
}

const contents = readFile(url);
this.requests.set(url, contents);
return contents;
}
return new Loader;
})();
};

const fileLoader = new ShellFileLoader();

class Driver {
constructor(benchmarks) {
Expand Down Expand Up @@ -248,7 +258,7 @@ class Driver {
performance.mark("update-ui");
benchmark.updateUIAfterRun();

if (isInBrowser) {
if (isInBrowser && globalThis.prefetchResources) {
const cache = JetStream.blobDataCache;
for (const file of benchmark.plan.files) {
const blobData = cache[file];
Expand Down Expand Up @@ -758,8 +768,9 @@ class Benchmark {
addScript(text);
} else {
const cache = JetStream.blobDataCache;
for (const file of this.plan.files)
addScriptWithURL(cache[file].blobURL);
for (const file of this.plan.files) {
addScriptWithURL(globalThis.prefetchResources ? cache[file].blobURL : file);
}
}

const promise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -814,6 +825,11 @@ class Benchmark {
}

async doLoadBlob(resource) {
const blobData = JetStream.blobDataCache[resource];
if (!globalThis.prefetchResources) {
blobData.blobURL = resource;
return blobData;
}
let response;
let tries = 3;
while (tries--) {
Expand All @@ -830,7 +846,6 @@ class Benchmark {
throw new Error("Fetch failed");
}
const blob = await response.blob();
const blobData = JetStream.blobDataCache[resource];
blobData.blob = blob;
blobData.blobURL = URL.createObjectURL(blob);
return blobData;
Expand Down
8 changes: 6 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ if (typeof runMode !== "undefined" && runMode == "RAMification")
globalThis.RAMification = true;
if ("--ramification" in cliFlags)
globalThis.RAMification = true;
if ("--no-prefetch:" in cliFlags)
globalThis.prefetchResources = false;
if (cliArgs.length)
globalThis.testList = cliArgs;

Expand All @@ -78,9 +80,11 @@ if ("--help" in cliFlags) {
console.log("");

console.log("Options:");
console.log(" --iteration-count: Set the default iteration count.");
console.log(" --worst-case-count: Set the default worst-case count");
console.log(" --iteration-count: Set the default iteration count.");
console.log(" --worst-case-count: Set the default worst-case count");
console.log(" --dump-json-results: Print summary json to the console.");
console.log(" --ramification: Enable ramification support. See RAMification.py for more details.");
console.log(" --no-prefetch: Do not prefetch resources. Will add network overhead to measurements!");
console.log("");

console.log("Available tags:");
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"test:firefox": "node tests/run.mjs --browser firefox",
"test:safari": "node tests/run.mjs --browser safari",
"test:edge": "node tests/run.mjs --browser edge",
"test:shell": "npm run test:v8 && npm run test:jsc && npm run test:spidermonkey",
"test:v8": "node tests/run-shell.mjs --shell v8",
"test:jsc": "node tests/run-shell.mjs --shell jsc",
"test:spidermonkey": "node tests/run-shell.mjs --shell spidermonkey"
Expand Down
1 change: 1 addition & 0 deletions shell-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const isInBrowser = false;
console = {
log: globalThis?.console?.log ?? print,
error: globalThis?.console?.error ?? print,
warn: globalThis?.console?.warn ?? print,
}

const isD8 = typeof Realm !== "undefined";
Expand Down
1 change: 1 addition & 0 deletions tests/run-shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async function runTests() {
let success = true;
success &&= await runTest("Run UnitTests", () => sh(shellBinary, UNIT_TEST_PATH));
success &&= await runCLITest("Run Single Suite", shellBinary, "proxy-mobx");
success &&= await runCLITest("Run Tag No Prefetch", shellBinary, "proxy", "--no-prefetch");
success &&= await runCLITest("Run Disabled Suite", shellBinary, "disabled");
success &&= await runCLITest("Run Default Suite", shellBinary);
if (!success)
Expand Down
10 changes: 7 additions & 3 deletions tests/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ const server = await serve(PORT);
async function runTests() {
let success = true;
try {
success &&= await runTest("Run Single Suite", () => testEnd2End({ test: "proxy-mobx" }));
success &&= await runTest("Run Disabled Suite", () => testEnd2End({ tag: "disabled" }));
success &&= await runTest("Run Default Suite", () => testEnd2End());
success &&= await runEnd2EndTest("Run Single Suite", { test: "proxy-mobx" });
success &&= await runEnd2EndTest("Run Tag No Prefetch", { tag: "proxy", prefetchResources:"false"});
success &&= await runEnd2EndTest("Run Disabled Suite", { tag: "disabled" });
success &&= await runEnd2EndTest("Run Default Suite");
} finally {
server.close();
}
if (!success)
process.exit(1);
}

async function runEnd2EndTest(name, params) {
return runTest(name, () => testEnd2End(params));
}

async function testEnd2End(params) {
const driver = await new Builder().withCapabilities(capabilities).build();
Expand Down
Loading