Skip to content

Commit c67fcf1

Browse files
committed
Address review comments
1 parent 3ad618a commit c67fcf1

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

JetStreamDriver.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const defaultIterationCount = 120;
3131
const defaultWorstCaseCount = 4;
3232

3333
if (!JetStreamParams.prefetchResources)
34-
console.warn("Disabling resource prefetching! All compressed files must have been decompressed using `node utils/compress.mjs -d`");
34+
console.warn("Disabling resource prefetching! All compressed files must have been decompressed using `node utils/compress.mjs -d -k`");
3535

3636
if (!isInBrowser && JetStreamParams.prefetchResources) {
3737
// Use the wasm compiled zlib as a polyfill when decompression stream is
@@ -158,9 +158,8 @@ function isCompressed(name) {
158158
}
159159

160160
function uncompressedName(name) {
161-
if (name.endsWith(".z"))
162-
return name.slice(0, -2);
163-
return name;
161+
console.assert(isCompressed(name));
162+
return name.slice(0, -2);
164163
}
165164

166165
// TODO: Cleanup / remove / merge. This is only used for caching loads in the
@@ -624,7 +623,7 @@ class Scripts {
624623
class ShellScripts extends Scripts {
625624
constructor() {
626625
super();
627-
this.prefetchedResources = [];
626+
this.prefetchedResources = Object.create(null);;
628627
}
629628

630629
run() {
@@ -661,12 +660,9 @@ class ShellScripts extends Scripts {
661660
globalObject.ShellTextDecoder = TextDecoder;
662661
// Store shellPrefetchedResources on ShellPrefetchedResources so that
663662
// getBinary and getString can find them.
664-
globalObject.ShellPrefetchedResources = {};
665-
for (const [name, value] of this.prefetchedResources) {
666-
globalObject.ShellPrefetchedResources[name] = value;
667-
}
663+
globalObject.ShellPrefetchedResources = this.prefetchedResources;
668664
} else {
669-
console.assert(this.prefetchedResources.length === 0, "Unexpected prefetched resources");
665+
console.assert(Object.values(this.prefetchedResources).length === 0, "Unexpected prefetched resources");
670666
}
671667

672668
globalObject.performance ??= performance;
@@ -677,7 +673,9 @@ class ShellScripts extends Scripts {
677673
}
678674

679675
addPrefetchedResources(prefetchedResources) {
680-
this.prefetchedResources.push(...prefetchedResources);
676+
for (let [file, bytes] of Object.entries(prefetchedResources)) {
677+
this.prefetchedResources[file] = bytes;
678+
}
681679
}
682680

683681
add(text) {
@@ -1090,11 +1088,9 @@ class Benchmark {
10901088

10911089
console.assert(this.preloads === null, "This initialization should be called only once.");
10921090
this.preloads = [];
1093-
this.shellPrefetchedResources = [];
1091+
this.shellPrefetchedResources = Object.create(null);
10941092
if (this.plan.preload) {
1095-
for (let name of Object.getOwnPropertyNames(this.plan.preload)) {
1096-
let file = this.plan.preload[name];
1097-
1093+
for (let [name, file] of Object.entries(this.plan.preload)) {
10981094
const compressed = isCompressed(file);
10991095
if (compressed && !JetStreamParams.prefetchResources) {
11001096
file = uncompressedName(file);
@@ -1105,7 +1101,7 @@ class Benchmark {
11051101
if (compressed) {
11061102
bytes = zlib.decompress(bytes);
11071103
}
1108-
this.shellPrefetchedResources.push([file, bytes]);
1104+
this.shellPrefetchedResources[file] = bytes;
11091105
}
11101106

11111107
this.preloads.push([name, file]);
@@ -1354,14 +1350,14 @@ class AsyncBenchmark extends DefaultBenchmark {
13541350
} else {
13551351
str += `
13561352
JetStream.getBinary = async function(path) {
1357-
if (ShellPrefetchedResources) {
1353+
if ("ShellPrefetchedResources" in globalThis) {
13581354
return ShellPrefetchedResources[path];
13591355
}
13601356
return new Int8Array(read(path, "binary"));
13611357
};
13621358
13631359
JetStream.getString = async function(path) {
1364-
if (ShellPrefetchedResources) {
1360+
if ("ShellPrefetchedResources" in globalThis) {
13651361
return new ShellTextDecoder().decode(ShellPrefetchedResources[path]);
13661362
}
13671363
return read(path);

0 commit comments

Comments
 (0)