perf: eliminate layout thrashing and array allocations during drawing

This commit is contained in:
ruinivist
2026-06-02 07:59:39 +00:00
parent d8d917d315
commit fdcda7a3c2
3 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -28,7 +28,8 @@ function sceneFromEditor(
files: BinaryFiles,
): ScenePayload {
return {
elements: [...elements],
// ⚡ Bolt: Excalidraw passes immutable arrays, avoid copying it on every onChange event
elements: elements as unknown[],
appState: appState as unknown as Record<string, unknown>,
files: files as unknown as Record<string, unknown>,
};
+10
View File
@@ -33,10 +33,20 @@ export function useThemeTokenSync(
return;
}
// ⚡ Bolt: Read all tokens first to avoid layout thrashing
const computedStyles = window.getComputedStyle(excalidrawRoot);
const updates: Array<[string, string]> = [];
for (const [sourceToken, targetToken] of EXCALIDRAW_THEME_TOKEN_MAP) {
const value = computedStyles.getPropertyValue(sourceToken).trim();
if (value) {
updates.push([targetToken, value]);
}
}
// ⚡ Bolt: Write in a separate pass, skipping unchanged values
for (const [targetToken, value] of updates) {
if (appShell.style.getPropertyValue(targetToken) !== value) {
appShell.style.setProperty(targetToken, value);
}
}