@@ -169,7 +169,7 @@ export function check_dirtiness(reaction) {
169
169
170
170
if ( ( flags & DISCONNECTED ) !== 0 ) {
171
171
for ( i = 0 ; i < dependencies . length ; i ++ ) {
172
- ( dependencies [ i ] . reactions ??= new Set ( ) ) . add ( reaction ) ;
172
+ ( dependencies [ i ] . reactions ??= [ ] ) . push ( reaction ) ;
173
173
}
174
174
175
175
reaction . f ^= DISCONNECTED ;
@@ -188,11 +188,11 @@ export function check_dirtiness(reaction) {
188
188
189
189
if ( is_unowned ) {
190
190
// TODO is there a more logical place to do this work?
191
- if ( ! current_skip_reaction && ! dependency ?. reactions ?. has ( reaction ) ) {
191
+ if ( ! current_skip_reaction && ! dependency ?. reactions ?. includes ( reaction ) ) {
192
192
// If we are working with an unowned signal as part of an effect (due to !current_skip_reaction)
193
193
// and the version hasn't changed, we still need to check that this reaction
194
194
// if linked to the dependency source – otherwise future updates will not be caught.
195
- ( dependency . reactions ??= new Set ( ) ) . add ( reaction ) ;
195
+ ( dependency . reactions ??= [ ] ) . push ( reaction ) ;
196
196
}
197
197
}
198
198
}
@@ -291,26 +291,9 @@ export function update_reaction(reaction) {
291
291
var deps = reaction . deps ;
292
292
293
293
if ( new_deps !== null ) {
294
- var dependency ;
295
294
var i ;
296
295
297
- if ( deps !== null ) {
298
- /** All dependencies of the reaction, including those tracked on the previous run */
299
- var array = skipped_deps === 0 ? new_deps : deps . slice ( 0 , skipped_deps ) . concat ( new_deps ) ;
300
-
301
- // If we have more than 16 elements in the array then use a Set for faster performance
302
- // TODO: evaluate if we should always just use a Set or not here?
303
- var set = array . length > 16 ? new Set ( array ) : null ;
304
-
305
- // Remove dependencies that should no longer be tracked
306
- for ( i = skipped_deps ; i < deps . length ; i ++ ) {
307
- dependency = deps [ i ] ;
308
-
309
- if ( set !== null ? ! set . has ( dependency ) : ! array . includes ( dependency ) ) {
310
- remove_reaction ( reaction , dependency ) ;
311
- }
312
- }
313
- }
296
+ remove_reactions ( reaction , skipped_deps ) ;
314
297
315
298
if ( deps !== null && skipped_deps > 0 ) {
316
299
deps . length = skipped_deps + new_deps . length ;
@@ -323,7 +306,7 @@ export function update_reaction(reaction) {
323
306
324
307
if ( ! current_skip_reaction ) {
325
308
for ( i = skipped_deps ; i < deps . length ; i ++ ) {
326
- ( deps [ i ] . reactions ??= new Set ( ) ) . add ( reaction ) ;
309
+ ( deps [ i ] . reactions ??= [ ] ) . push ( reaction ) ;
327
310
}
328
311
}
329
312
} else if ( deps !== null && skipped_deps < deps . length ) {
@@ -350,9 +333,16 @@ export function update_reaction(reaction) {
350
333
function remove_reaction ( signal , dependency ) {
351
334
let reactions = dependency . reactions ;
352
335
if ( reactions !== null ) {
353
- reactions . delete ( signal ) ;
354
- if ( reactions . size === 0 ) {
355
- reactions = dependency . reactions = null ;
336
+ var index = reactions . indexOf ( signal ) ;
337
+ if ( index !== - 1 ) {
338
+ var new_length = reactions . length - 1 ;
339
+ if ( new_length === 0 ) {
340
+ reactions = dependency . reactions = null ;
341
+ } else {
342
+ // Swap with last element and then remove.
343
+ reactions [ index ] = reactions [ new_length ] ;
344
+ reactions . pop ( ) ;
345
+ }
356
346
}
357
347
}
358
348
// If the derived has no reactions, then we can disconnect it from the graph,
@@ -377,19 +367,8 @@ export function remove_reactions(signal, start_index) {
377
367
var dependencies = signal . deps ;
378
368
if ( dependencies === null ) return ;
379
369
380
- var active_dependencies = start_index === 0 ? null : dependencies . slice ( 0 , start_index ) ;
381
- var seen = new Set ( ) ;
382
-
383
370
for ( var i = start_index ; i < dependencies . length ; i ++ ) {
384
- var dependency = dependencies [ i ] ;
385
-
386
- if ( seen . has ( dependency ) ) continue ;
387
- seen . add ( dependency ) ;
388
-
389
- // Avoid removing a reaction if we know that it is active (start_index will not be 0)
390
- if ( active_dependencies === null || ! active_dependencies . includes ( dependency ) ) {
391
- remove_reaction ( signal , dependency ) ;
392
- }
371
+ remove_reaction ( signal , dependencies [ i ] ) ;
393
372
}
394
373
}
395
374
@@ -726,16 +705,10 @@ export function get(signal) {
726
705
// rather than updating `new_deps`, which creates GC cost
727
706
if ( new_deps === null && deps !== null && deps [ skipped_deps ] === signal ) {
728
707
skipped_deps ++ ;
729
- }
730
-
731
- // Otherwise, create or push to `new_deps`, but only if this
732
- // dependency wasn't the last one that was accessed
733
- else if ( deps === null || skipped_deps === 0 || deps [ skipped_deps - 1 ] !== signal ) {
734
- if ( new_deps === null ) {
735
- new_deps = [ signal ] ;
736
- } else if ( new_deps [ new_deps . length - 1 ] !== signal ) {
737
- new_deps . push ( signal ) ;
738
- }
708
+ } else if ( new_deps === null ) {
709
+ new_deps = [ signal ] ;
710
+ } else {
711
+ new_deps . push ( signal ) ;
739
712
}
740
713
741
714
if (
0 commit comments