perf: O(n²)→O(n) Map lookups for legacy reactive statements (#18602)

pull/18680/merge
Liam O'Dea 4 days ago committed by GitHub
parent cac27c783e
commit f5f70343df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
perf: O(n²)→O(n) Map lookups for legacy `$:` reactive statement ordering

@ -1318,7 +1318,8 @@ function order_reactive_statements(unsorted_reactive_declarations) {
* @returns
*/
const add_declaration = (node, declaration) => {
if ([...reactive_declarations.values()].includes(declaration)) return;
// Visited set: each ReactiveStatement is stored under exactly one LabeledStatement node
if (reactive_declarations.has(node)) return;
for (const binding of declaration.dependencies) {
if (declaration.assignments.has(binding)) continue;

@ -247,11 +247,11 @@ export function client_component(analysis, options) {
}
for (const [node] of analysis.reactive_statements) {
const statement = [...state.legacy_reactive_statements].find(([n]) => n === node);
const statement = state.legacy_reactive_statements.get(node);
if (statement === undefined) {
throw new Error('Could not find reactive statement');
}
instance.body.push(statement[1]);
instance.body.push(statement);
}
if (analysis.reactive_statements.size > 0) {

@ -148,7 +148,7 @@ export function server_component(analysis, options) {
const legacy_reactive_declarations = [];
for (const [node] of analysis.reactive_statements) {
const statement = [...state.legacy_reactive_statements].find(([n]) => n === node);
const statement = state.legacy_reactive_statements.get(node);
if (statement === undefined) {
throw new Error('Could not find reactive statement');
}
@ -165,7 +165,7 @@ export function server_component(analysis, options) {
}
}
instance.body.push(statement[1]);
instance.body.push(statement);
}
if (legacy_reactive_declarations.length > 0) {

Loading…
Cancel
Save