@esportsplus/reactivity 0.18.1 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/system.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isObject } from '@esportsplus/utilities';
2
2
  import { COMPUTED, SIGNAL, STABILIZER_IDLE, STABILIZER_RESCHEDULE, STABILIZER_RUNNING, STABILIZER_SCHEDULED, STATE_CHECK, STATE_DIRTY, STATE_IN_HEAP, STATE_NONE, STATE_NOTIFY_MASK, STATE_RECOMPUTING } from './constants.js';
3
- let depth = 0, heap = new Array(64), heap_i = 0, heap_n = 0, microtask = queueMicrotask, notified = false, observer = null, scope = null, stabilizer = STABILIZER_IDLE, version = 0;
3
+ let depth = 0, heap = new Array(64), heap_i = 0, heap_n = 0, linkPool = [], linkPoolMax = 1000, microtask = queueMicrotask, notified = false, observer = null, scope = null, stabilizer = STABILIZER_IDLE, version = 0;
4
4
  function cleanup(computed) {
5
5
  if (!computed.cleanup) {
6
6
  return;
@@ -82,15 +82,23 @@ function link(dep, sub) {
82
82
  prevSub.sub === sub) {
83
83
  return;
84
84
  }
85
- let newLink = sub.depsTail =
86
- dep.subsTail = {
87
- dep,
88
- sub,
89
- nextDep,
90
- prevSub,
91
- nextSub: null,
92
- version
93
- };
85
+ let pooled = linkPool.pop(), newLink = sub.depsTail =
86
+ dep.subsTail = pooled
87
+ ? (pooled.dep = dep,
88
+ pooled.sub = sub,
89
+ pooled.nextDep = nextDep,
90
+ pooled.prevSub = prevSub,
91
+ pooled.nextSub = null,
92
+ pooled.version = version,
93
+ pooled)
94
+ : {
95
+ dep,
96
+ sub,
97
+ nextDep,
98
+ prevSub,
99
+ nextSub: null,
100
+ version
101
+ };
94
102
  if (prevDep) {
95
103
  prevDep.nextDep = newLink;
96
104
  }
@@ -214,6 +222,11 @@ function unlink(link) {
214
222
  else if ((dep.subs = nextSub) === null && 'fn' in dep) {
215
223
  dispose(dep);
216
224
  }
225
+ if (linkPool.length < linkPoolMax) {
226
+ link.dep = link.sub = null;
227
+ link.nextDep = link.nextSub = link.prevSub = null;
228
+ linkPool.push(link);
229
+ }
217
230
  return nextDep;
218
231
  }
219
232
  function update(computed) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "ICJR",
3
3
  "dependencies": {
4
4
  "@esportsplus/custom-function": "^0.0.13",
5
- "@esportsplus/utilities": "^0.22.2"
5
+ "@esportsplus/utilities": "^0.25.0"
6
6
  },
7
7
  "devDependencies": {
8
8
  "@esportsplus/typescript": "^0.9.2"
@@ -12,7 +12,7 @@
12
12
  "private": false,
13
13
  "type": "module",
14
14
  "types": "build/index.d.ts",
15
- "version": "0.18.1",
15
+ "version": "0.19.0",
16
16
  "scripts": {
17
17
  "build": "tsc && tsc-alias",
18
18
  "-": "-"
package/src/system.ts CHANGED
@@ -11,6 +11,8 @@ let depth = 0,
11
11
  heap: (Computed<unknown> | undefined)[] = new Array(64),
12
12
  heap_i = 0,
13
13
  heap_n = 0,
14
+ linkPool: Link[] = [],
15
+ linkPoolMax = 1000,
14
16
  microtask = queueMicrotask,
15
17
  notified = false,
16
18
  observer: Computed<unknown> | null = null,
@@ -135,16 +137,25 @@ function link<T>(dep: Signal<T> | Computed<T>, sub: Computed<T>) {
135
137
  return;
136
138
  }
137
139
 
138
- let newLink =
140
+ let pooled = linkPool.pop(),
141
+ newLink =
139
142
  sub.depsTail =
140
- dep.subsTail = {
141
- dep,
142
- sub,
143
- nextDep,
144
- prevSub,
145
- nextSub: null,
146
- version
147
- };
143
+ dep.subsTail = pooled
144
+ ? (pooled.dep = dep,
145
+ pooled.sub = sub,
146
+ pooled.nextDep = nextDep,
147
+ pooled.prevSub = prevSub,
148
+ pooled.nextSub = null,
149
+ pooled.version = version,
150
+ pooled)
151
+ : {
152
+ dep,
153
+ sub,
154
+ nextDep,
155
+ prevSub,
156
+ nextSub: null,
157
+ version
158
+ };
148
159
 
149
160
  if (prevDep) {
150
161
  prevDep.nextDep = newLink;
@@ -314,6 +325,13 @@ function unlink(link: Link): Link | null {
314
325
  dispose(dep);
315
326
  }
316
327
 
328
+ // Release link back to pool
329
+ if (linkPool.length < linkPoolMax) {
330
+ link.dep = link.sub = null as any;
331
+ link.nextDep = link.nextSub = link.prevSub = null;
332
+ linkPool.push(link);
333
+ }
334
+
317
335
  return nextDep;
318
336
  }
319
337