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