Merge branch 'parallelize-async-work' of https://github.com/sveltejs/svelte into parallelize-async-work

parallelize-async-work
ComputerGuy 6 days ago
commit e80ab33d50

@ -38,9 +38,10 @@ export function is_state_source(binding, analysis) {
*/ */
export function can_be_parallelized(expression, scope, analysis, bindings) { export function can_be_parallelized(expression, scope, analysis, bindings) {
let has_closures = false; let has_closures = false;
let should_stop = false;
/** @type {Set<string>} */ /** @type {Set<string>} */
const references = new Set(); const references = new Set();
walk(expression, null, { walk(/** @type {Node} */ (expression), null, {
ArrowFunctionExpression(_, { stop }) { ArrowFunctionExpression(_, { stop }) {
has_closures = true; has_closures = true;
stop(); stop();
@ -53,9 +54,25 @@ export function can_be_parallelized(expression, scope, analysis, bindings) {
if (is_reference(node, /** @type {Node} */ (path.at(-1)))) { if (is_reference(node, /** @type {Node} */ (path.at(-1)))) {
references.add(node.name); references.add(node.name);
} }
},
MemberExpression(node, { stop }) {
should_stop = true;
stop();
},
CallExpression(node, { stop }) {
should_stop = true;
stop();
},
NewExpression(node, { stop }) {
should_stop = true;
stop();
},
StaticBlock(node, { stop }) {
has_closures = true;
stop();
} }
}); });
if (has_closures) { if (has_closures || should_stop) {
return false; return false;
} }
for (const reference of references) { for (const reference of references) {

@ -153,7 +153,7 @@ export function Program(node, context) {
); );
} else { } else {
const pattern = b.array_pattern(chunk.declarators.map(({ id }) => id)); const pattern = b.array_pattern(chunk.declarators.map(({ id }) => id));
const init = b.call('$.all', b.array(chunk.declarators.map(({ init }) => init))); const init = b.call('$.all', ...chunk.declarators.map(({ init }) => init));
body.push(b.declaration(chunk.kind, [b.declarator(pattern, b.await(init))])); body.push(b.declaration(chunk.kind, [b.declarator(pattern, b.await(init))]));
} }
} }

Loading…
Cancel
Save