@glimt/record 0.0.27 → 0.0.29

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,89 @@ 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
+ "storm duration:",
9470
+ Date.now() - this.stormInfo.startedAt,
9471
+ "ms"
9472
+ );
9473
+ clearTimeout(this.stormInfo.timeout);
9474
+ this.stormInfo = null;
9475
+ if (!stormExceededLimit) {
9476
+ let muts = [];
9477
+ for (const batch of this.stormBatches) {
9478
+ muts.push(...batch.mutations);
9479
+ }
9480
+ this.stormBatches = [];
9481
+ this.processInternalMutations(muts, true);
9482
+ } else {
9483
+ this.stormBatches = [];
9484
+ takeFullSnapshot();
9485
+ }
9486
+ });
9487
+ __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
9488
+ if (!overrideStorm && (this.stormInfo != null || muts.length >= this.stormSettings.batchSize)) {
9489
+ this.handleStormMutations(muts);
9490
+ return;
9491
+ }
9428
9492
  const start = performance.now();
9429
- let uniqueTypes = [];
9430
- for (const mut of mutations) {
9431
- const mutStart = performance.now();
9493
+ for (const mut of muts) {
9432
9494
  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
9495
  }
9447
9496
  console.log(
9448
- mutations.length,
9497
+ muts.length,
9449
9498
  "mutations processed in",
9450
9499
  performance.now() - start,
9451
9500
  "ms",
9452
- "types:",
9453
- uniqueTypes
9501
+ "overrideStorm",
9502
+ overrideStorm
9454
9503
  );
9455
- window.temp_perf_store = this.tempPerfStore;
9456
9504
  this.emit();
9457
9505
  });
9506
+ __publicField(this, "processMutations", (mutations) => {
9507
+ this.processInternalMutations(mutations);
9508
+ });
9458
9509
  __publicField(this, "emit", () => {
9459
9510
  if (this.frozen || this.locked) {
9460
9511
  return;