@glimt/record 0.0.64 → 0.0.66

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/dist/record.cjs CHANGED
@@ -1993,16 +1993,6 @@ function serializeNodeWithId(n2, options) {
1993
1993
  debugging.store[n2.nodeName].push(took);
1994
1994
  if (debugging.index % 5e3 === 0) {
1995
1995
  debugging.index = 0;
1996
- const avgs = Object.entries(debugging.store).map(([key, values]) => {
1997
- return {
1998
- tagName: key,
1999
- avg: values.reduce((a2, b) => a2 + b, 0) / values.length,
2000
- max: Math.max(...values),
2001
- min: Math.min(...values)
2002
- };
2003
- });
2004
- console.log("last 5000 avgs");
2005
- console.table(avgs);
2006
1996
  debugging.store = {};
2007
1997
  }
2008
1998
  return serializedNode;
@@ -10337,6 +10327,49 @@ const _StormSnapshotManager = class _StormSnapshotManager2 {
10337
10327
  __publicField(_StormSnapshotManager, "instance");
10338
10328
  let StormSnapshotManager = _StormSnapshotManager;
10339
10329
  const stormSnapshotManager = new StormSnapshotManager();
10330
+ class MutationRateLimiter {
10331
+ constructor() {
10332
+ __publicField(this, "mutTracker");
10333
+ __publicField(this, "interval", 50);
10334
+ __publicField(this, "limit", 150);
10335
+ __publicField(this, "inGlobalStorm", false);
10336
+ debugLog(`MutationRateLimiter, init`);
10337
+ this.reset();
10338
+ }
10339
+ reset() {
10340
+ this.mutTracker = {
10341
+ muts: 0,
10342
+ ts: -1
10343
+ };
10344
+ }
10345
+ isStorming(muts) {
10346
+ const now = Date.now();
10347
+ if (this.inGlobalStorm) {
10348
+ if (now - this.mutTracker.ts > this.interval) {
10349
+ this.inGlobalStorm = false;
10350
+ debugLog(`MutationRateLimiter, detected global storm over`);
10351
+ return false;
10352
+ }
10353
+ return true;
10354
+ }
10355
+ if (this.mutTracker.ts === -1) {
10356
+ this.mutTracker.muts = muts;
10357
+ } else {
10358
+ if (now - this.mutTracker.ts <= this.interval) {
10359
+ this.mutTracker.muts += muts;
10360
+ if (this.mutTracker.muts >= this.limit) {
10361
+ this.inGlobalStorm = true;
10362
+ this.reset();
10363
+ debugLog(`MutationRateLimiter, detected global rolling storm`);
10364
+ return true;
10365
+ }
10366
+ }
10367
+ }
10368
+ this.mutTracker.ts = now;
10369
+ return false;
10370
+ }
10371
+ }
10372
+ const mutationRateLimiter = new MutationRateLimiter();
10340
10373
  function isNodeInLinkedList(n2) {
10341
10374
  return "__ln" in n2;
10342
10375
  }
@@ -10476,9 +10509,9 @@ class MutationBuffer {
10476
10509
  __publicField(this, "rollingMutTracker", {
10477
10510
  accumlativeMuts: 0,
10478
10511
  ts: -1,
10479
- interval: 10
10512
+ interval: 50
10480
10513
  });
10481
- __publicField(this, "handleStormMutations", (muts) => {
10514
+ __publicField(this, "handleStormMutations", (muts, canFinishStorm = true) => {
10482
10515
  const time = Date.now();
10483
10516
  if (this.stormInfo == null) {
10484
10517
  debugLog(
@@ -10504,7 +10537,7 @@ class MutationBuffer {
10504
10537
  });
10505
10538
  }
10506
10539
  clearTimeout(this.stormInfo.timeout);
10507
- if (muts.length < this.stormSettings.batchSize) {
10540
+ if (canFinishStorm && muts.length < this.stormSettings.batchSize) {
10508
10541
  this.handleStormFinish();
10509
10542
  } else {
10510
10543
  this.stormInfo.timeout = setTimeout(
@@ -10543,30 +10576,20 @@ class MutationBuffer {
10543
10576
  }
10544
10577
  });
10545
10578
  __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
10546
- console.log("muts", muts.length);
10579
+ console.log(
10580
+ "muts",
10581
+ muts.length,
10582
+ JSON.parse(JSON.stringify(this.rollingMutTracker))
10583
+ );
10547
10584
  if (!overrideStorm) {
10585
+ const isStorming = mutationRateLimiter.isStorming(muts.length);
10586
+ if (isStorming) {
10587
+ this.handleStormMutations(muts, false);
10588
+ return;
10589
+ }
10548
10590
  if (this.stormInfo != null || muts.length >= this.stormSettings.batchSize) {
10549
10591
  this.handleStormMutations(muts);
10550
10592
  }
10551
- if (this.stormInfo == null) {
10552
- const now = Date.now();
10553
- if (this.rollingMutTracker.ts === -1) {
10554
- this.rollingMutTracker.accumlativeMuts = muts.length;
10555
- } else {
10556
- if (now - this.rollingMutTracker.ts <= this.rollingMutTracker.interval) {
10557
- this.rollingMutTracker.accumlativeMuts += muts.length;
10558
- if (this.rollingMutTracker.accumlativeMuts >= this.stormSettings.batchSize) {
10559
- debugLog(`Mutation storm through rolling detected.`);
10560
- this.handleStormMutations(muts);
10561
- this.rollingMutTracker.accumlativeMuts = 0;
10562
- this.rollingMutTracker.ts = -1;
10563
- }
10564
- } else {
10565
- this.rollingMutTracker.accumlativeMuts = 0;
10566
- }
10567
- }
10568
- this.rollingMutTracker.ts = now;
10569
- }
10570
10593
  return;
10571
10594
  }
10572
10595
  for (const mut of muts) {