@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.
@@ -2026,16 +2026,6 @@ function serializeNodeWithId(n2, options) {
2026
2026
  debugging.store[n2.nodeName].push(took);
2027
2027
  if (debugging.index % 5e3 === 0) {
2028
2028
  debugging.index = 0;
2029
- const avgs = Object.entries(debugging.store).map(([key, values]) => {
2030
- return {
2031
- tagName: key,
2032
- avg: values.reduce((a2, b) => a2 + b, 0) / values.length,
2033
- max: Math.max(...values),
2034
- min: Math.min(...values)
2035
- };
2036
- });
2037
- console.log("last 5000 avgs");
2038
- console.table(avgs);
2039
2029
  debugging.store = {};
2040
2030
  }
2041
2031
  return serializedNode;
@@ -10379,6 +10369,49 @@ const _StormSnapshotManager = class _StormSnapshotManager2 {
10379
10369
  __publicField(_StormSnapshotManager, "instance");
10380
10370
  let StormSnapshotManager = _StormSnapshotManager;
10381
10371
  const stormSnapshotManager = new StormSnapshotManager();
10372
+ class MutationRateLimiter {
10373
+ constructor() {
10374
+ __publicField(this, "mutTracker");
10375
+ __publicField(this, "interval", 50);
10376
+ __publicField(this, "limit", 150);
10377
+ __publicField(this, "inGlobalStorm", false);
10378
+ debugLog(`MutationRateLimiter, init`);
10379
+ this.reset();
10380
+ }
10381
+ reset() {
10382
+ this.mutTracker = {
10383
+ muts: 0,
10384
+ ts: -1
10385
+ };
10386
+ }
10387
+ isStorming(muts) {
10388
+ const now = Date.now();
10389
+ if (this.inGlobalStorm) {
10390
+ if (now - this.mutTracker.ts > this.interval) {
10391
+ this.inGlobalStorm = false;
10392
+ debugLog(`MutationRateLimiter, detected global storm over`);
10393
+ return false;
10394
+ }
10395
+ return true;
10396
+ }
10397
+ if (this.mutTracker.ts === -1) {
10398
+ this.mutTracker.muts = muts;
10399
+ } else {
10400
+ if (now - this.mutTracker.ts <= this.interval) {
10401
+ this.mutTracker.muts += muts;
10402
+ if (this.mutTracker.muts >= this.limit) {
10403
+ this.inGlobalStorm = true;
10404
+ this.reset();
10405
+ debugLog(`MutationRateLimiter, detected global rolling storm`);
10406
+ return true;
10407
+ }
10408
+ }
10409
+ }
10410
+ this.mutTracker.ts = now;
10411
+ return false;
10412
+ }
10413
+ }
10414
+ const mutationRateLimiter = new MutationRateLimiter();
10382
10415
  function isNodeInLinkedList(n2) {
10383
10416
  return "__ln" in n2;
10384
10417
  }
@@ -10518,9 +10551,9 @@ class MutationBuffer {
10518
10551
  __publicField(this, "rollingMutTracker", {
10519
10552
  accumlativeMuts: 0,
10520
10553
  ts: -1,
10521
- interval: 10
10554
+ interval: 50
10522
10555
  });
10523
- __publicField(this, "handleStormMutations", (muts) => {
10556
+ __publicField(this, "handleStormMutations", (muts, canFinishStorm = true) => {
10524
10557
  const time = Date.now();
10525
10558
  if (this.stormInfo == null) {
10526
10559
  debugLog(
@@ -10546,7 +10579,7 @@ class MutationBuffer {
10546
10579
  });
10547
10580
  }
10548
10581
  clearTimeout(this.stormInfo.timeout);
10549
- if (muts.length < this.stormSettings.batchSize) {
10582
+ if (canFinishStorm && muts.length < this.stormSettings.batchSize) {
10550
10583
  this.handleStormFinish();
10551
10584
  } else {
10552
10585
  this.stormInfo.timeout = setTimeout(
@@ -10585,30 +10618,20 @@ class MutationBuffer {
10585
10618
  }
10586
10619
  });
10587
10620
  __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
10588
- console.log("muts", muts.length);
10621
+ console.log(
10622
+ "muts",
10623
+ muts.length,
10624
+ JSON.parse(JSON.stringify(this.rollingMutTracker))
10625
+ );
10589
10626
  if (!overrideStorm) {
10627
+ const isStorming = mutationRateLimiter.isStorming(muts.length);
10628
+ if (isStorming) {
10629
+ this.handleStormMutations(muts, false);
10630
+ return;
10631
+ }
10590
10632
  if (this.stormInfo != null || muts.length >= this.stormSettings.batchSize) {
10591
10633
  this.handleStormMutations(muts);
10592
10634
  }
10593
- if (this.stormInfo == null) {
10594
- const now = Date.now();
10595
- if (this.rollingMutTracker.ts === -1) {
10596
- this.rollingMutTracker.accumlativeMuts = muts.length;
10597
- } else {
10598
- if (now - this.rollingMutTracker.ts <= this.rollingMutTracker.interval) {
10599
- this.rollingMutTracker.accumlativeMuts += muts.length;
10600
- if (this.rollingMutTracker.accumlativeMuts >= this.stormSettings.batchSize) {
10601
- debugLog(`Mutation storm through rolling detected.`);
10602
- this.handleStormMutations(muts);
10603
- this.rollingMutTracker.accumlativeMuts = 0;
10604
- this.rollingMutTracker.ts = -1;
10605
- }
10606
- } else {
10607
- this.rollingMutTracker.accumlativeMuts = 0;
10608
- }
10609
- }
10610
- this.rollingMutTracker.ts = now;
10611
- }
10612
10635
  return;
10613
10636
  }
10614
10637
  for (const mut of muts) {