@glimt/record 0.0.27 → 0.0.28

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
@@ -9423,38 +9423,86 @@ class MutationBuffer {
9423
9423
  __publicField(this, "canvasManager");
9424
9424
  __publicField(this, "processedNodeManager");
9425
9425
  __publicField(this, "unattachedDoc");
9426
- __publicField(this, "tempPerfStore", {});
9427
- __publicField(this, "processMutations", (mutations) => {
9426
+ __publicField(this, "stormBatches", []);
9427
+ __publicField(this, "stormInfo");
9428
+ __publicField(this, "stormSettings", {
9429
+ batchSize: 300,
9430
+ timeout: 50,
9431
+ mutationLimit: 1500
9432
+ });
9433
+ __publicField(this, "handleStormMutations", (muts) => {
9434
+ const time = Date.now();
9435
+ if (this.stormInfo == null) {
9436
+ console.log("detected probable mutation storm start");
9437
+ this.stormInfo = {
9438
+ startedAt: time,
9439
+ totalMutations: 0,
9440
+ timeout: setTimeout(this.handleStormFinish, this.stormSettings.timeout),
9441
+ stormExceededLimit: false
9442
+ };
9443
+ }
9444
+ this.stormInfo.totalMutations += muts.length;
9445
+ console.log("current storm mutations", this.stormInfo.totalMutations);
9446
+ if (this.stormInfo.totalMutations >= this.stormSettings.mutationLimit) {
9447
+ this.stormInfo.stormExceededLimit = true;
9448
+ this.stormBatches = [];
9449
+ } else {
9450
+ this.stormBatches.push({
9451
+ ts: time,
9452
+ mutations: muts
9453
+ });
9454
+ }
9455
+ if (muts.length < this.stormSettings.batchSize) {
9456
+ clearTimeout(this.stormInfo.timeout);
9457
+ this.handleStormFinish();
9458
+ }
9459
+ });
9460
+ __publicField(this, "handleStormFinish", () => {
9461
+ if (!this.stormInfo) return;
9462
+ const { stormExceededLimit } = this.stormInfo;
9463
+ console.log(
9464
+ "mutation storm finished",
9465
+ "totalMutations:",
9466
+ this.stormInfo.totalMutations,
9467
+ "stormExceededLimit:",
9468
+ stormExceededLimit
9469
+ );
9470
+ clearTimeout(this.stormInfo.timeout);
9471
+ this.stormInfo = null;
9472
+ if (!stormExceededLimit) {
9473
+ let muts = [];
9474
+ for (const batch of this.stormBatches) {
9475
+ muts.push(...batch.mutations);
9476
+ }
9477
+ this.stormBatches = [];
9478
+ this.processInternalMutations(muts, true);
9479
+ } else {
9480
+ this.stormBatches = [];
9481
+ takeFullSnapshot();
9482
+ }
9483
+ });
9484
+ __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
9485
+ if (!overrideStorm && (this.stormInfo != null || muts.length >= this.stormSettings.batchSize)) {
9486
+ this.handleStormMutations(muts);
9487
+ return;
9488
+ }
9428
9489
  const start = performance.now();
9429
- let uniqueTypes = [];
9430
- for (const mut of mutations) {
9431
- const mutStart = performance.now();
9490
+ for (const mut of muts) {
9432
9491
  this.processMutation(mut);
9433
- const took = performance.now() - mutStart;
9434
- if (!uniqueTypes.includes(mut.type)) uniqueTypes.push(mut.type);
9435
- if (!(mut.type in this.tempPerfStore)) {
9436
- this.tempPerfStore[mut.type] = {
9437
- avg: 0,
9438
- times: []
9439
- };
9440
- }
9441
- this.tempPerfStore[mut.type].times.push(took);
9442
- if (this.tempPerfStore[mut.type].times.length > 1e3) {
9443
- this.tempPerfStore[mut.type].times.shift();
9444
- }
9445
- this.tempPerfStore[mut.type].avg = this.tempPerfStore[mut.type].times.reduce((a2, b) => a2 + b, 0) / this.tempPerfStore[mut.type].times.length;
9446
9492
  }
9447
9493
  console.log(
9448
- mutations.length,
9494
+ muts.length,
9449
9495
  "mutations processed in",
9450
9496
  performance.now() - start,
9451
9497
  "ms",
9452
- "types:",
9453
- uniqueTypes
9498
+ "overrideStorm",
9499
+ overrideStorm
9454
9500
  );
9455
- window.temp_perf_store = this.tempPerfStore;
9456
9501
  this.emit();
9457
9502
  });
9503
+ __publicField(this, "processMutations", (mutations) => {
9504
+ this.processInternalMutations(mutations);
9505
+ });
9458
9506
  __publicField(this, "emit", () => {
9459
9507
  if (this.frozen || this.locked) {
9460
9508
  return;