Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,7 @@ let BENCHMARKS = [
new AsyncBenchmark({
name: "jsdom-d3-startup",
files: [
"./startup-helper/StartupBenchmark.js",
"./utils/StartupBenchmark.js",
"./jsdom-d3-startup/benchmark.js",
],
preload: {
Expand All @@ -2274,12 +2274,13 @@ let BENCHMARKS = [
new AsyncBenchmark({
name: "web-ssr",
files: [
"./utils/StartupBenchmark.js",
"./web-ssr/benchmark.js",
],
preload: {
// Debug Sources for nicer profiling.
// BUNDLE_BLOB: "./web-ssr/dist/bundle.js",
BUNDLE_BLOB: "./web-ssr/dist/bundle.min.js",
// BUNDLE: "./web-ssr/dist/bundle.js",
BUNDLE: "./web-ssr/dist/bundle.min.js",
},
tags: ["default", "js", "web", "ssr"],
iterations: 30,
Expand Down Expand Up @@ -2876,7 +2877,7 @@ let BENCHMARKS = [


const PRISM_JS_FILES = [
"./startup-helper/StartupBenchmark.js",
"./utils/StartupBenchmark.js",
"./prismjs/benchmark.js",
];
const PRISM_JS_PRELOADS = {
Expand Down
2 changes: 1 addition & 1 deletion jsdom-d3-startup/webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function createConfig({ filename, minify }) {
use: {
loader: "babel-loader",
options: {
plugins: [ "../startup-helper/BabelCacheBuster.mjs" ],
plugins: [ "../utils/BabelCacheBuster.mjs" ],
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion prismjs/webpack.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import { fileURLToPath } from "url";
import TerserPlugin from "terser-webpack-plugin";
import CacheBusterCommentPlugin from "../startup-helper/BabelCacheBuster.mjs";
import CacheBusterCommentPlugin from "../utils/BabelCacheBuster.mjs";
import UnicodeEscapePlugin from "@dapplets/unicode-escape-webpack-plugin";
import { LicenseWebpackPlugin } from "license-webpack-plugin";

Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

load("utils/shell-config.js");
load("utils/params.js");
load("startup-helper/StartupBenchmark.js");
load("utils/StartupBenchmark.js");
load("JetStreamDriver.js");

function assertTrue(condition, message) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ class StartupBenchmark {
}

async init() {
if (!JetStream.preload.BUNDLE) {
throw new Error("Missing JetStream.preload.BUNDLE");
}
this.#sourceCode = await JetStream.getString(JetStream.preload.BUNDLE);
if (!this.sourceCode || !this.sourceCode.length) {
throw new Error("Couldn't load JetStream.preload.BUNDLE");
}

const cacheCommentCount = this.sourceCode.match(
CACHE_BUST_COMMENT_RE
).length;
Expand Down
60 changes: 12 additions & 48 deletions web-ssr/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,25 @@ globalThis.console = {
globalThis.clearTimeout = function () { };


function quickHash(str) {
let hash = 5381;
let i = str.length;
while (i > 0) {
hash = (hash * 33) ^ (str.charCodeAt(i) | 0);
i-= 919;
}
return hash | 0;
}

const CACHE_BUST_COMMENT = "/*ThouShaltNotCache*/";
const CACHE_BUST_COMMENT_RE = new RegExp(`\n${RegExp.escape(CACHE_BUST_COMMENT)}\n`, "g");

// JetStream benchmark.
class Benchmark {
class Benchmark extends StartupBenchmark {
// How many times (separate iterations) should we reuse the source code.
// Use 0 to skip.
CODE_REUSE_COUNT = 1;
iterationCount = 0;
iteration = 0;
lastResult = {};
sourceCode;
sourceHash = 0
iterationSourceCodes = [];

constructor({ iterationCount }) {
this.iterationCount = iterationCount
}

async init() {
this.sourceCode = await JetStream.getString(JetStream.preload.BUNDLE_BLOB);
this.expect("Cache Comment Count", this.sourceCode.match(CACHE_BUST_COMMENT_RE).length, 597);
for (let i = 0; i < this.iterationCount; i++)
this.iterationSourceCodes[i] = this.prepareCode(i);
}

prepareCode(iteration) {
if (!this.CODE_REUSE_COUNT)
return this.sourceCode;
// Alter the code per iteration to prevent caching.
const cacheId = Math.floor(iteration / this.CODE_REUSE_COUNT);
const previousSourceCode = this.iterationSourceCodes[cacheId];
if (previousSourceCode)
return previousSourceCode
const sourceCode = this.sourceCode.replaceAll(CACHE_BUST_COMMENT_RE, `/*${cacheId}*/`);
// Ensure efficient string representation.
this.sourceHash = quickHash(sourceCode);
return sourceCode;
constructor({iterationCount}) {
super({
iterationCount,
expectedCacheCommentCount: 597,
sourceCodeReuseCount: 1,
});
}

runIteration() {
let sourceCode = this.iterationSourceCodes[this.iteration];
runIteration(iteration) {
let sourceCode = this.iterationSourceCodes[iteration];
if (!sourceCode)
throw new Error(`Could not find source for iteration ${this.iteration}`);
throw new Error(`Could not find source for iteration ${iteration}`);
// Module in sourceCode it assigned to the ReactRenderTest variable.
let ReactRenderTest;

Expand All @@ -71,16 +36,15 @@ class Benchmark {
const runStart = performance.now();

this.lastResult = ReactRenderTest.renderTest();
this.lastResult.htmlHash = quickHash(this.lastResult.html);
this.lastResult.htmlHash = this.quickHash(this.lastResult.html);
const end = performance.now();

const loadTime = runStart - initStart;
const runTime = end - runStart;
// For local debugging:
// print(`Iteration ${this.iteration}:`);
// print(`Iteration ${iteration}:`);
// print(` Load time: ${loadTime.toFixed(2)}ms`);
// print(` Render time: ${runTime.toFixed(2)}ms`);
this.iteration++;
}

validate() {
Expand Down
4 changes: 2 additions & 2 deletions web-ssr/webpack.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function createConfig({ filename, minify }) {
}],
"@babel/preset-react"
],
plugins: [path.resolve(__dirname, "../startup-helper/BabelCacheBuster.mjs")],
plugins: [path.resolve(__dirname, "../utils/BabelCacheBuster.mjs")],
},
},
},
Expand All @@ -64,7 +64,7 @@ function createConfig({ filename, minify }) {
use: {
loader: "babel-loader",
options: {
plugins: [path.resolve(__dirname, "../startup-helper/BabelCacheBuster.mjs")],
plugins: [path.resolve(__dirname, "../utils/BabelCacheBuster.mjs")],
},
},
},
Expand Down
Loading