From 4110eaf45af369de5751fbec61417d96bb3eb398 Mon Sep 17 00:00:00 2001 From: Chris Mounce Date: Wed, 24 Sep 2025 08:55:22 -0700 Subject: [PATCH] Log timing info for document load --- src/components/App.tsx | 2 ++ src/components/Debug.tsx | 13 +++++++++++++ src/persistence.ts | 1 + src/sync.ts | 15 ++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/components/Debug.tsx diff --git a/src/components/App.tsx b/src/components/App.tsx index 80c1d0c..bd07cc7 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -11,6 +11,7 @@ import Editor from './Editor'; import { HashRouter, Route, useNavigate } from '@solidjs/router'; import { defaultVault } from '../sync'; import { getDocsMap } from '../vault'; +import DebugView from './Debug'; interface NavbarProps { fileId: Accessor; @@ -67,6 +68,7 @@ function App() { + ); } diff --git a/src/components/Debug.tsx b/src/components/Debug.tsx new file mode 100644 index 0000000..551e68b --- /dev/null +++ b/src/components/Debug.tsx @@ -0,0 +1,13 @@ +import { createSignal, For } from 'solid-js'; + +const [getDebugLogs, setDebugLogs] = createSignal([]); + +export function debugLog(message: string, ...args: any[]) { + const components = [message, ...args.map((x) => JSON.stringify(x))]; + const line = components.join(' '); + setDebugLogs([...getDebugLogs(), line]); +} + +export default function DebugView() { + return {(logLine) =>

{logLine}

}
; +} diff --git a/src/persistence.ts b/src/persistence.ts index 2875f2e..5ebc989 100644 --- a/src/persistence.ts +++ b/src/persistence.ts @@ -60,6 +60,7 @@ async function initialLoad(id: string): Promise { }; } +// @ts-ignore class BufferedWriter { private deltaBuffer: Uint8Array[]; private docId: string; diff --git a/src/sync.ts b/src/sync.ts index 5ce76d8..423bd16 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -3,6 +3,7 @@ import * as Y from 'yjs'; import { openDB, type DBSchema } from 'idb'; import { assert, generateId } from './util'; import { getDocsMap, getVaultMap, type DocMap } from './vault'; +import { debugLog } from './components/Debug'; const DB_NAME = 'synced-docs'; export const LOCAL_DELTA_STORE = 'local-updates'; @@ -59,16 +60,28 @@ export class LocalDocument { public static async load(id: string): Promise { // Build Y.Doc from records on disk + const startMs = performance.now(); const updates: Uint8Array[] = await docsDb.getAll( LOCAL_DELTA_STORE, IDBKeyRange.bound([id, -Infinity], [id, Infinity]) ); + const loadedMs = performance.now(); + const mergedUpdate = Y.mergeUpdates(updates); + const mergedMs = performance.now(); const ydoc = new Y.Doc(); - Y.applyUpdate(ydoc, Y.mergeUpdates(updates)); + Y.applyUpdate(ydoc, mergedUpdate); + const appliedMs = performance.now(); // Build LocalDocument instance const result = new LocalDocument(id, ydoc); result.totalUpdates = updates.length; + + // Emit debug timings + const timings = [loadedMs, mergedMs, appliedMs].map((x) => x - startMs); + debugLog( + `Loaded ${updates.length} updates for doc ${id}, load/merge/apply timings in ms`, + timings + ); return result; }