Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
760ef6f
adding web sssr
camillobruni Aug 7, 2025
47e0a16
wip
camillobruni Aug 7, 2025
f159ea6
adding stuff
camillobruni Aug 7, 2025
27f257f
fix
camillobruni Aug 7, 2025
062a4cc
update
camillobruni Aug 7, 2025
5b7a194
fixes
camillobruni Aug 7, 2025
cd91ad4
update
camillobruni Aug 7, 2025
5d1543e
Merge branch 'WebKit:main' into 2025-08-07_web_ssr
camillobruni Aug 7, 2025
ccecfa8
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni Aug 8, 2025
3f61cd5
Merge branch '2025-08-07_web_ssr' of github.com:camillobruni/JetStrea…
camillobruni Aug 8, 2025
dc87fee
update
camillobruni Aug 8, 2025
cb9badf
update
camillobruni Aug 8, 2025
8612487
add comment-injecting terser plugin
camillobruni Aug 10, 2025
384cb64
more
camillobruni Aug 10, 2025
3ed8ab4
update
camillobruni Aug 11, 2025
c6e4585
adding more files
camillobruni Aug 11, 2025
636d6a0
add CACHE_BUST_COMMENT counting
camillobruni Aug 11, 2025
34ce451
backup
camillobruni Aug 11, 2025
9c2717d
use RE to count comments
camillobruni Aug 11, 2025
31489cc
fixing
camillobruni Aug 11, 2025
6723625
update comment adder
camillobruni Aug 11, 2025
1b51510
rename
camillobruni Aug 11, 2025
3d865c1
renaming
camillobruni Aug 11, 2025
8ca7363
add more detail
camillobruni Aug 11, 2025
fa1ff84
update
camillobruni Aug 11, 2025
0bdc931
Merge remote-tracking branch 'webkit/main' into 2025-08-07_web_ssr
camillobruni Aug 12, 2025
56f014a
pre-format
camillobruni Aug 12, 2025
0eb7f42
pre-format
camillobruni Aug 12, 2025
edc344c
cleanup
camillobruni Aug 12, 2025
eecfae5
format
camillobruni Aug 12, 2025
b3f70ba
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni Aug 14, 2025
67e6f21
merge main and update quickHashing
camillobruni Aug 14, 2025
1a2d81c
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni Aug 15, 2025
989a607
upgrading project
camillobruni Aug 15, 2025
bafe536
update code
camillobruni Aug 15, 2025
27ac469
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni Aug 26, 2025
2a2fde1
conver to mjs
camillobruni Aug 26, 2025
5d40931
add UnicodeEscapePlugin
camillobruni Aug 26, 2025
06e3b3f
using cache-buster
camillobruni Aug 26, 2025
f3df267
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni Aug 26, 2025
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
13 changes: 13 additions & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,19 @@ let BENCHMARKS = [
],
tags: ["Default", "Proxy"],
}),
new AsyncBenchmark({
name: "web-ssr",
files: [
"./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",
},
tags: ["Default", "web", "ssr"],
iterations: 30,
}),
// Class fields
new DefaultBenchmark({
name: "raytrace-public-class-fields",
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
"local-web-server": "^5.4.0",
"prettier": "^2.8.3",
"selenium-webdriver": "^4.35.0"
},
"dependencies": {
"@dapplets/unicode-escape-webpack-plugin": "^0.1.1"
}
}
6 changes: 6 additions & 0 deletions web-ssr/babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
14 changes: 14 additions & 0 deletions web-ssr/benchmark-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// node standalone version of the benchmark for local testing.

import { renderTest } from "./src/react-render-test.cjs";

console.log("Starting TypeScript in-memory compilation benchmark...");
const startTime = performance.now();

renderTest();

const endTime = performance.now();
const duration = (endTime - startTime) / 1000;

console.log(`TypeScript compilation finished.`);
console.log(`Compilation took ${duration.toFixed(2)} seconds.`);
95 changes: 95 additions & 0 deletions web-ssr/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
globalThis.console = {
log() { },
warn() { },
assert(condition) {
if (!condition) throw new Error("Invalid assertion");
}
};

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 {
// 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;
}

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

let initStart = performance.now();
const res = eval(sourceCode);
const runStart = performance.now();

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

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

validate() {
this.expect("HTML length", this.lastResult.html.length, 183778);
this.expect("HTML hash", this.lastResult.htmlHash, 1177839858);
}

expect(name, value, expected) {
if (value != expected)
throw new Error(`Expected ${name} to be ${expected}, but got ${value}`);
}
}
29 changes: 29 additions & 0 deletions web-ssr/build/cache-buster-comment-plugin.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Babel plugin that adds CACHE_BUST_COMMENT to every function body.
const CACHE_BUST_COMMENT = "ThouShaltNotCache";


module.exports = function({ types: t }) {
return {
visitor: {
Function(path) {
const bodyPath = path.get("body");
// Handle arrow functions: () => "value"
// Convert them to block statements: () => { return "value"; }
if (!bodyPath.isBlockStatement()) {
const newBody = t.blockStatement([t.returnStatement(bodyPath.node)]);
path.set("body", newBody);
}

// Handle empty function bodies: function foo() {}
// Add an empty statement so we have a first node to attach the comment to.
if (path.get("body.body").length === 0) {
path.get("body").pushContainer("body", t.emptyStatement());
}

const firstNode = path.node.body.body[0];
t.addComment(firstNode, "leading", CACHE_BUST_COMMENT);

}
},
};
};
1,221 changes: 1,221 additions & 0 deletions web-ssr/dist/bundle.js

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions web-ssr/dist/bundle.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license React
* react-dom-server-legacy.browser.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-dom-server.browser.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-dom.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react.production.js
*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
1 change: 1 addition & 0 deletions web-ssr/dist/bundle.js.map

Large diffs are not rendered by default.

Loading
Loading