cojson 0.1.10 → 0.1.12

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/src/sync.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  WritableStreamDefaultWriter,
10
10
  } from "isomorphic-streams";
11
11
  import { RawCoID, SessionID } from "./ids.js";
12
+ import { stableStringify } from "./fastJsonStableStringify.js";
12
13
 
13
14
  export type CoValueKnownState = {
14
15
  id: RawCoID;
@@ -445,12 +446,26 @@ export class SyncManager {
445
446
  const newTransactions =
446
447
  newContentForSession.newTransactions.slice(alreadyKnownOffset);
447
448
 
448
- const success = coValue.tryAddTransactions(
449
+ const before = performance.now();
450
+ const success = await coValue.tryAddTransactionsAsync(
449
451
  sessionID,
450
452
  newTransactions,
451
453
  undefined,
452
454
  newContentForSession.lastSignature
453
455
  );
456
+ const after = performance.now();
457
+ if (after - before > 10) {
458
+ const totalTxLength = newTransactions.map(t => stableStringify(t)!.length).reduce((a, b) => a + b, 0);
459
+ console.log(
460
+ "Adding incoming transactions took",
461
+ after - before,
462
+ "ms",
463
+ totalTxLength,
464
+ "bytes = ",
465
+ "bandwidth: MB/s",
466
+ (1000 * totalTxLength / (after - before)) / (1024 * 1024)
467
+ );
468
+ }
454
469
 
455
470
  if (!success) {
456
471
  console.error("Failed to add transactions", newTransactions);