-
Notifications
You must be signed in to change notification settings - Fork 15
New Workload: React Server Side Rendering Startup #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
760ef6f
adding web sssr
camillobruni 47e0a16
wip
camillobruni f159ea6
adding stuff
camillobruni 27f257f
fix
camillobruni 062a4cc
update
camillobruni 5b7a194
fixes
camillobruni cd91ad4
update
camillobruni 5d1543e
Merge branch 'WebKit:main' into 2025-08-07_web_ssr
camillobruni ccecfa8
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni 3f61cd5
Merge branch '2025-08-07_web_ssr' of github.com:camillobruni/JetStrea…
camillobruni dc87fee
update
camillobruni cb9badf
update
camillobruni 8612487
add comment-injecting terser plugin
camillobruni 384cb64
more
camillobruni 3ed8ab4
update
camillobruni c6e4585
adding more files
camillobruni 636d6a0
add CACHE_BUST_COMMENT counting
camillobruni 34ce451
backup
camillobruni 9c2717d
use RE to count comments
camillobruni 31489cc
fixing
camillobruni 6723625
update comment adder
camillobruni 1b51510
rename
camillobruni 3d865c1
renaming
camillobruni 8ca7363
add more detail
camillobruni fa1ff84
update
camillobruni 0bdc931
Merge remote-tracking branch 'webkit/main' into 2025-08-07_web_ssr
camillobruni 56f014a
pre-format
camillobruni 0eb7f42
pre-format
camillobruni edc344c
cleanup
camillobruni eecfae5
format
camillobruni b3f70ba
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni 67e6f21
merge main and update quickHashing
camillobruni 1a2d81c
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni 989a607
upgrading project
camillobruni bafe536
update code
camillobruni 27ac469
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni 2a2fde1
conver to mjs
camillobruni 5d40931
add UnicodeEscapePlugin
camillobruni 06e3b3f
using cache-buster
camillobruni f3df267
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni 1c5a3eb
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni 4a3f849
Merge branch 'main' into 2025-08-07_web_ssr
camillobruni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
}, | ||
}; | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to play with the worstCase counts since there's not a lot of iterations here. 2-3 seems standard. We can do that in a follow up though (please file an issue though).