Skip to content

Commit 05a2c01

Browse files
scttcpercodexdomenic
authored
Deduplicate generated CSS property metadata
Co-authored-by: codex <[email protected]> Co-authored-by: Domenic Denicola <[email protected]>
1 parent 1efa190 commit 05a2c01

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎scripts/generate-css-style-properties.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,24 @@ module.exports = new Map([
127127
${resolvedValueResolvers.join(",\n ")}
128128
]);
129129
`;
130+
// Share identical metadata to reduce generated code and allocations.
131+
const uniqueMetadata = new Map();
132+
const metadataEntries = metadata.map(([property, opts]) => {
133+
const source = JSON.stringify(opts);
134+
if (!uniqueMetadata.has(source)) {
135+
uniqueMetadata.set(source, `metadata${uniqueMetadata.size}`);
136+
}
137+
return `["${property}", ${uniqueMetadata.get(source)}]`;
138+
});
130139
const metadataOutput = `"use strict";
131-
module.exports = new Map(${JSON.stringify(metadata, undefined, 2)});
140+
141+
// Metadata objects, including nested values, are shared across properties.
142+
// Treat them as immutable.
143+
${Array.from(uniqueMetadata, ([source, identifier]) => `const ${identifier} = ${source};`).join("\n")}
144+
145+
module.exports = new Map([
146+
${metadataEntries.join(",\n ")}
147+
]);
132148
`;
133149
return Promise.all([
134150
fs.writeFile(

0 commit comments

Comments
 (0)