Log timing info for document load
This commit is contained in:
@@ -11,6 +11,7 @@ import Editor from './Editor';
|
|||||||
import { HashRouter, Route, useNavigate } from '@solidjs/router';
|
import { HashRouter, Route, useNavigate } from '@solidjs/router';
|
||||||
import { defaultVault } from '../sync';
|
import { defaultVault } from '../sync';
|
||||||
import { getDocsMap } from '../vault';
|
import { getDocsMap } from '../vault';
|
||||||
|
import DebugView from './Debug';
|
||||||
|
|
||||||
interface NavbarProps {
|
interface NavbarProps {
|
||||||
fileId: Accessor<string | null>;
|
fileId: Accessor<string | null>;
|
||||||
@@ -67,6 +68,7 @@ function App() {
|
|||||||
<HashRouter root={Layout}>
|
<HashRouter root={Layout}>
|
||||||
<Route path="" component={Chooser} />
|
<Route path="" component={Chooser} />
|
||||||
<Route path="doc/:id" component={Editor} />
|
<Route path="doc/:id" component={Editor} />
|
||||||
|
<Route path="debug" component={DebugView} />
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { createSignal, For } from 'solid-js';
|
||||||
|
|
||||||
|
const [getDebugLogs, setDebugLogs] = createSignal<string[]>([]);
|
||||||
|
|
||||||
|
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 <For each={getDebugLogs()}>{(logLine) => <p>{logLine}</p>}</For>;
|
||||||
|
}
|
||||||
@@ -60,6 +60,7 @@ async function initialLoad(id: string): Promise<State> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
class BufferedWriter {
|
class BufferedWriter {
|
||||||
private deltaBuffer: Uint8Array[];
|
private deltaBuffer: Uint8Array[];
|
||||||
private docId: string;
|
private docId: string;
|
||||||
|
|||||||
+14
-1
@@ -3,6 +3,7 @@ import * as Y from 'yjs';
|
|||||||
import { openDB, type DBSchema } from 'idb';
|
import { openDB, type DBSchema } from 'idb';
|
||||||
import { assert, generateId } from './util';
|
import { assert, generateId } from './util';
|
||||||
import { getDocsMap, getVaultMap, type DocMap } from './vault';
|
import { getDocsMap, getVaultMap, type DocMap } from './vault';
|
||||||
|
import { debugLog } from './components/Debug';
|
||||||
|
|
||||||
const DB_NAME = 'synced-docs';
|
const DB_NAME = 'synced-docs';
|
||||||
export const LOCAL_DELTA_STORE = 'local-updates';
|
export const LOCAL_DELTA_STORE = 'local-updates';
|
||||||
@@ -59,16 +60,28 @@ export class LocalDocument {
|
|||||||
|
|
||||||
public static async load(id: string): Promise<LocalDocument> {
|
public static async load(id: string): Promise<LocalDocument> {
|
||||||
// Build Y.Doc from records on disk
|
// Build Y.Doc from records on disk
|
||||||
|
const startMs = performance.now();
|
||||||
const updates: Uint8Array[] = await docsDb.getAll(
|
const updates: Uint8Array[] = await docsDb.getAll(
|
||||||
LOCAL_DELTA_STORE,
|
LOCAL_DELTA_STORE,
|
||||||
IDBKeyRange.bound([id, -Infinity], [id, Infinity])
|
IDBKeyRange.bound([id, -Infinity], [id, Infinity])
|
||||||
);
|
);
|
||||||
|
const loadedMs = performance.now();
|
||||||
|
const mergedUpdate = Y.mergeUpdates(updates);
|
||||||
|
const mergedMs = performance.now();
|
||||||
const ydoc = new Y.Doc();
|
const ydoc = new Y.Doc();
|
||||||
Y.applyUpdate(ydoc, Y.mergeUpdates(updates));
|
Y.applyUpdate(ydoc, mergedUpdate);
|
||||||
|
const appliedMs = performance.now();
|
||||||
|
|
||||||
// Build LocalDocument instance
|
// Build LocalDocument instance
|
||||||
const result = new LocalDocument(id, ydoc);
|
const result = new LocalDocument(id, ydoc);
|
||||||
result.totalUpdates = updates.length;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user