chore: M4 counts the presence changes of a drag; measured again on test-filius

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 07:32:49 +00:00
co-authored by Claude Opus 5.5
parent 44b3f3ccb2
commit 5fa590246c
+9 -3
View File
@@ -2,8 +2,10 @@
// is, and how many updates dragging a device makes. Mia drags a device in a // is, and how many updates dragging a device makes. Mia drags a device in a
// real browser for two seconds at 60 pointer moves a second (as a finger or // real browser for two seconds at 60 pointer moves a second (as a finger or
// a mouse does); a second person, watching through /sync, counts the updates // a mouse does); a second person, watching through /sync, counts the updates
// that arrive and their bytes. Then the document's size as F holds it: fresh, // that arrive and their bytes, and the presence changes Mia's editor sends
// after the drags, and as one update (what a new person loads). // meanwhile (since F5.6d the drag goes there, the document gets its end).
// Then the document's size as F holds it: fresh, after the drags, and as one
// update (what a new person loads).
// //
// npx vite-node tools/live/m4.ts // npx vite-node tools/live/m4.ts
@@ -28,8 +30,12 @@ try {
watcher.doc.on('update', (update: Uint8Array, origin: unknown) => { watcher.doc.on('update', (update: Uint8Array, origin: unknown) => {
if (origin !== null && typeof origin === 'object') arrivals.push({ at: performance.now(), bytes: update.length }); if (origin !== null && typeof origin === 'object') arrivals.push({ at: performance.now(), bytes: update.length });
}); });
let presence = 0;
const awareness = watcher.provider.awareness;
awareness.on('change', ({ updated }: { updated: number[] }) => (presence += updated.filter((client) => client !== awareness.clientID).length));
for (const name of ['Heimrouter', 'webserver.de (120.130.140.80)', 'iPad 1']) { for (const name of ['Heimrouter', 'webserver.de (120.130.140.80)', 'iPad 1']) {
arrivals.length = 0; arrivals.length = 0;
presence = 0;
const from = await onDevice(page, example.graph.nodes.find((node) => node.displayName === name)!.id); const from = await onDevice(page, example.graph.nodes.find((node) => node.displayName === name)!.id);
await page.mouse.move(from.x, from.y); await page.mouse.move(from.x, from.y);
await page.mouse.down(); await page.mouse.down();
@@ -45,7 +51,7 @@ try {
await new Promise((resolve) => setTimeout(resolve, 1500)); await new Promise((resolve) => setTimeout(resolve, 1500));
const bytes = arrivals.reduce((sum, each) => sum + each.bytes, 0); const bytes = arrivals.reduce((sum, each) => sum + each.bytes, 0);
console.log( console.log(
`drag ${name.padEnd(30)} ${dragged.toFixed(1)} s: ${arrivals.length} updates (${(arrivals.length / dragged).toFixed(0)}/s), ${bytes} bytes, ${(bytes / Math.max(1, arrivals.length)).toFixed(0)} per update`, `drag ${name.padEnd(30)} ${dragged.toFixed(1)} s: ${arrivals.length} updates (${(arrivals.length / dragged).toFixed(0)}/s), ${bytes} bytes, ${(bytes / Math.max(1, arrivals.length)).toFixed(0)} per update; ${presence} presence changes (${(presence / dragged).toFixed(0)}/s)`,
); );
} }
console.log(`after the drags: ${Y.encodeStateAsUpdate(watcher.doc).length} bytes as one update`); console.log(`after the drags: ${Y.encodeStateAsUpdate(watcher.doc).length} bytes as one update`);