Skip to content

Commit

Permalink
[Fizz] Optimize end tags chunks (#27522)
Browse files Browse the repository at this point in the history
Implements `endChunkForTag` to make writing end tags faster

DiffTrain build for [8c85b02](8c85b02)
  • Loading branch information
gnoff committed Oct 20, 2023
1 parent 293517d commit 5a422ba
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 164 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f172fa74610df623f1e82997ba66337452deeaa1
8c85b02996b940d63f961f835348a0dd0045d3b6
2 changes: 1 addition & 1 deletion compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-modern-6d0bc8c7";
var ReactVersion = "18.3.0-www-modern-f6a06001";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9848,7 +9848,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-75350665",
version: "18.3.0-www-modern-27dfd1a3",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1302 = {
Expand Down Expand Up @@ -9879,7 +9879,7 @@ var internals$jscomp$inline_1302 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-75350665"
reconcilerVersion: "18.3.0-www-modern-27dfd1a3"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1303 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
37 changes: 21 additions & 16 deletions compiled/facebook-www/ReactDOMServer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-classic-89c1183f";
var ReactVersion = "18.3.0-www-classic-3ac6c75e";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -4167,7 +4167,7 @@ function pushStyleImpl(target, props) {
}

pushInnerHTML(target, innerHTML, children);
target.push(endTag1, stringToChunk("style"), endTag2);
target.push(endChunkForTag("style"));
return null;
}

Expand Down Expand Up @@ -4483,7 +4483,7 @@ function pushTitleImpl(target, props) {
}

pushInnerHTML(target, innerHTML, children);
target.push(endTag1, stringToChunk("title"), endTag2);
target.push(endChunkForTag("title"));
return null;
}

Expand Down Expand Up @@ -4656,7 +4656,7 @@ function pushScriptImpl(target, props) {
target.push(stringToChunk(encodeHTMLTextNode(children)));
}

target.push(endTag1, stringToChunk("script"), endTag2);
target.push(endChunkForTag("script"));
return null;
}

Expand Down Expand Up @@ -5080,8 +5080,19 @@ function pushStartInstance(

return pushStartGenericElement(target, props, type);
}
var endTag1 = stringToPrecomputedChunk("</");
var endTag2 = stringToPrecomputedChunk(">");
var endTagCache = new Map();

function endChunkForTag(tag) {
var chunk = endTagCache.get(tag);

if (chunk === undefined) {
chunk = stringToPrecomputedChunk("</" + tag + ">");
endTagCache.set(tag, chunk);
}

return chunk;
}

function pushEndInstance(target, type, props, resumableState, formatContext) {
switch (type) {
// When float is on we expect title and script tags to always be pushed in
Expand Down Expand Up @@ -5136,7 +5147,7 @@ function pushEndInstance(target, type, props, resumableState, formatContext) {
break;
}

target.push(endTag1, stringToChunk(type), endTag2);
target.push(endChunkForTag(type));
}

function writeBootstrap(destination, renderState) {
Expand Down Expand Up @@ -6052,9 +6063,7 @@ function writePreamble(
// if the main content contained the </head> it would also have provided a
// <head>. This means that all the content inside <html> is either <body> or
// invalid HTML
writeChunk(destination, endTag1);
writeChunk(destination, stringToChunk("head"));
writeChunk(destination, endTag2);
writeChunk(destination, endChunkForTag("head"));
}
} // We don't bother reporting backpressure at the moment because we expect to
// flush the entire preamble in a single pass. This probably should be modified
Expand Down Expand Up @@ -6111,15 +6120,11 @@ function writeHoistables(destination, resumableState, renderState) {
}
function writePostamble(destination, resumableState) {
if (resumableState.hasBody) {
writeChunk(destination, endTag1);
writeChunk(destination, stringToChunk("body"));
writeChunk(destination, endTag2);
writeChunk(destination, endChunkForTag("body"));
}

if (resumableState.hasHtml) {
writeChunk(destination, endTag1);
writeChunk(destination, stringToChunk("html"));
writeChunk(destination, endTag2);
writeChunk(destination, endChunkForTag("html"));
}
}
var arrayFirstOpenBracket = stringToPrecomputedChunk("[");
Expand Down
37 changes: 21 additions & 16 deletions compiled/facebook-www/ReactDOMServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (__DEV__) {
var React = require("react");
var ReactDOM = require("react-dom");

var ReactVersion = "18.3.0-www-modern-6d0bc8c7";
var ReactVersion = "18.3.0-www-modern-f6a06001";

// This refers to a WWW module.
var warningWWW = require("warning");
Expand Down Expand Up @@ -4167,7 +4167,7 @@ function pushStyleImpl(target, props) {
}

pushInnerHTML(target, innerHTML, children);
target.push(endTag1, stringToChunk("style"), endTag2);
target.push(endChunkForTag("style"));
return null;
}

Expand Down Expand Up @@ -4483,7 +4483,7 @@ function pushTitleImpl(target, props) {
}

pushInnerHTML(target, innerHTML, children);
target.push(endTag1, stringToChunk("title"), endTag2);
target.push(endChunkForTag("title"));
return null;
}

Expand Down Expand Up @@ -4656,7 +4656,7 @@ function pushScriptImpl(target, props) {
target.push(stringToChunk(encodeHTMLTextNode(children)));
}

target.push(endTag1, stringToChunk("script"), endTag2);
target.push(endChunkForTag("script"));
return null;
}

Expand Down Expand Up @@ -5080,8 +5080,19 @@ function pushStartInstance(

return pushStartGenericElement(target, props, type);
}
var endTag1 = stringToPrecomputedChunk("</");
var endTag2 = stringToPrecomputedChunk(">");
var endTagCache = new Map();

function endChunkForTag(tag) {
var chunk = endTagCache.get(tag);

if (chunk === undefined) {
chunk = stringToPrecomputedChunk("</" + tag + ">");
endTagCache.set(tag, chunk);
}

return chunk;
}

function pushEndInstance(target, type, props, resumableState, formatContext) {
switch (type) {
// When float is on we expect title and script tags to always be pushed in
Expand Down Expand Up @@ -5136,7 +5147,7 @@ function pushEndInstance(target, type, props, resumableState, formatContext) {
break;
}

target.push(endTag1, stringToChunk(type), endTag2);
target.push(endChunkForTag(type));
}

function writeBootstrap(destination, renderState) {
Expand Down Expand Up @@ -6052,9 +6063,7 @@ function writePreamble(
// if the main content contained the </head> it would also have provided a
// <head>. This means that all the content inside <html> is either <body> or
// invalid HTML
writeChunk(destination, endTag1);
writeChunk(destination, stringToChunk("head"));
writeChunk(destination, endTag2);
writeChunk(destination, endChunkForTag("head"));
}
} // We don't bother reporting backpressure at the moment because we expect to
// flush the entire preamble in a single pass. This probably should be modified
Expand Down Expand Up @@ -6111,15 +6120,11 @@ function writeHoistables(destination, resumableState, renderState) {
}
function writePostamble(destination, resumableState) {
if (resumableState.hasBody) {
writeChunk(destination, endTag1);
writeChunk(destination, stringToChunk("body"));
writeChunk(destination, endTag2);
writeChunk(destination, endChunkForTag("body"));
}

if (resumableState.hasHtml) {
writeChunk(destination, endTag1);
writeChunk(destination, stringToChunk("html"));
writeChunk(destination, endTag2);
writeChunk(destination, endChunkForTag("html"));
}
}
var arrayFirstOpenBracket = stringToPrecomputedChunk("[");
Expand Down
Loading

0 comments on commit 5a422ba

Please sign in to comment.