Skip to content

Commit 555ab68

Browse files
committed
optimize
1 parent f959baf commit 555ab68

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/svelte/src/internal/client/runtime.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,16 @@ function execute_signal_fn(signal) {
350350
if (current_dependencies !== null) {
351351
let i;
352352
if (dependencies !== null) {
353-
for (i = current_dependencies_index; i < dependencies.length; i++) {
353+
const dep_length = dependencies.length;
354+
// If we have more than 16 elements in the array then use a Set for faster performance
355+
// TODO: evaluate if we should always just use a Set or not here?
356+
const current_dependencies_set = dep_length > 16 ? new Set(current_dependencies) : null;
357+
for (i = current_dependencies_index; i < dep_length; i++) {
354358
const dependency = dependencies[i];
355-
if (!current_dependencies.includes(dependency)) {
359+
if (
360+
(current_dependencies_set !== null && !current_dependencies_set.has(dependency)) ||
361+
!current_dependencies.includes(dependency)
362+
) {
356363
remove_consumer(signal, dependency, false);
357364
}
358365
}

0 commit comments

Comments
 (0)