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