Skip to content

Commit 521bb6f

Browse files
committed
perf: use has for effect sets
1 parent 908d030 commit 521bb6f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/qwik/src/core/reactive-primitives/cleanup.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function clearAllEffects(container: Container, consumer: Consumer): void
4646

4747
function clearSignal(container: Container, producer: SignalImpl, effect: EffectSubscription) {
4848
const effects = producer.$effects$;
49-
if (effects) {
49+
if (effects && effects.has(effect)) {
5050
effects.delete(effect);
5151
}
5252

@@ -61,11 +61,11 @@ function clearAsyncComputedSignal(
6161
effect: EffectSubscription
6262
) {
6363
const effects = producer.$effects$;
64-
if (effects) {
64+
if (effects && effects.has(effect)) {
6565
effects.delete(effect);
6666
}
6767
const pendingEffects = producer.$loadingEffects$;
68-
if (pendingEffects) {
68+
if (pendingEffects && pendingEffects.has(effect)) {
6969
pendingEffects.delete(effect);
7070
}
7171
}
@@ -74,7 +74,9 @@ function clearStore(producer: StoreHandler, effect: EffectSubscription) {
7474
const effects = producer?.$effects$;
7575
if (effects) {
7676
for (const propEffects of effects.values()) {
77-
propEffects.delete(effect);
77+
if (propEffects.has(effect)) {
78+
propEffects.delete(effect);
79+
}
7880
}
7981
}
8082
}

packages/qwik/src/core/reactive-primitives/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ export const ensureContainsSubscription = (
5454
array: Set<EffectSubscription>,
5555
effectSubscription: EffectSubscription
5656
) => {
57-
array.add(effectSubscription);
57+
!array.has(effectSubscription) && array.add(effectSubscription);
5858
};
5959

6060
/** Ensure the item is in back refs set */
6161
export const ensureContainsBackRef = (array: EffectSubscription, value: any) => {
6262
array[EffectSubscriptionProp.BACK_REF] ||= new Set();
63-
array[EffectSubscriptionProp.BACK_REF].add(value);
63+
!array[EffectSubscriptionProp.BACK_REF].has(value) &&
64+
array[EffectSubscriptionProp.BACK_REF].add(value);
6465
};
6566

6667
export const addQrlToSerializationCtx = (

0 commit comments

Comments
 (0)