@@ -31,7 +31,7 @@ const defaultIterationCount = 120;
31
31
const defaultWorstCaseCount = 4 ;
32
32
33
33
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 `" ) ;
35
35
36
36
if ( ! isInBrowser && JetStreamParams . prefetchResources ) {
37
37
// Use the wasm compiled zlib as a polyfill when decompression stream is
@@ -158,9 +158,8 @@ function isCompressed(name) {
158
158
}
159
159
160
160
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 ) ;
164
163
}
165
164
166
165
// TODO: Cleanup / remove / merge. This is only used for caching loads in the
@@ -624,7 +623,7 @@ class Scripts {
624
623
class ShellScripts extends Scripts {
625
624
constructor ( ) {
626
625
super ( ) ;
627
- this . prefetchedResources = [ ] ;
626
+ this . prefetchedResources = Object . create ( null ) ; ;
628
627
}
629
628
630
629
run ( ) {
@@ -661,12 +660,9 @@ class ShellScripts extends Scripts {
661
660
globalObject . ShellTextDecoder = TextDecoder ;
662
661
// Store shellPrefetchedResources on ShellPrefetchedResources so that
663
662
// 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 ;
668
664
} else {
669
- console . assert ( this . prefetchedResources . length === 0 , "Unexpected prefetched resources" ) ;
665
+ console . assert ( Object . values ( this . prefetchedResources ) . length === 0 , "Unexpected prefetched resources" ) ;
670
666
}
671
667
672
668
globalObject . performance ??= performance ;
@@ -677,7 +673,9 @@ class ShellScripts extends Scripts {
677
673
}
678
674
679
675
addPrefetchedResources ( prefetchedResources ) {
680
- this . prefetchedResources . push ( ...prefetchedResources ) ;
676
+ for ( let [ file , bytes ] of Object . entries ( prefetchedResources ) ) {
677
+ this . prefetchedResources [ file ] = bytes ;
678
+ }
681
679
}
682
680
683
681
add ( text ) {
@@ -1090,11 +1088,9 @@ class Benchmark {
1090
1088
1091
1089
console . assert ( this . preloads === null , "This initialization should be called only once." ) ;
1092
1090
this . preloads = [ ] ;
1093
- this . shellPrefetchedResources = [ ] ;
1091
+ this . shellPrefetchedResources = Object . create ( null ) ;
1094
1092
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 ) ) {
1098
1094
const compressed = isCompressed ( file ) ;
1099
1095
if ( compressed && ! JetStreamParams . prefetchResources ) {
1100
1096
file = uncompressedName ( file ) ;
@@ -1105,7 +1101,7 @@ class Benchmark {
1105
1101
if ( compressed ) {
1106
1102
bytes = zlib . decompress ( bytes ) ;
1107
1103
}
1108
- this . shellPrefetchedResources . push ( [ file , bytes ] ) ;
1104
+ this . shellPrefetchedResources [ file ] = bytes ;
1109
1105
}
1110
1106
1111
1107
this . preloads . push ( [ name , file ] ) ;
@@ -1354,14 +1350,14 @@ class AsyncBenchmark extends DefaultBenchmark {
1354
1350
} else {
1355
1351
str += `
1356
1352
JetStream.getBinary = async function(path) {
1357
- if (ShellPrefetchedResources) {
1353
+ if (" ShellPrefetchedResources" in globalThis ) {
1358
1354
return ShellPrefetchedResources[path];
1359
1355
}
1360
1356
return new Int8Array(read(path, "binary"));
1361
1357
};
1362
1358
1363
1359
JetStream.getString = async function(path) {
1364
- if (ShellPrefetchedResources) {
1360
+ if (" ShellPrefetchedResources" in globalThis ) {
1365
1361
return new ShellTextDecoder().decode(ShellPrefetchedResources[path]);
1366
1362
}
1367
1363
return read(path);
0 commit comments