Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Make timeline perf tests measure the chain walk, not the host (#4759)

Nick Gomezf9f2403057b3
diff --git a/knip.config.ts b/knip.config.ts
index 5b8951125..659eef71e 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -143,11 +143,15 @@ export default {
'packages/server': {
entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],
project: 'src/**',
- ignoreDependencies: ['@types/shell-quote'],
+ ignoreDependencies: [
+ '@types/shell-quote',
+ ],
},
'packages/cli': {
entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],
- ignoreDependencies: ['yjs'],
+ ignoreDependencies: [
+ 'yjs',
+ ],
},
'packages/desktop': {
entry: [
diff --git a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
index 8a60e5826..a28cc2b18 100644
--- a/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
+++ b/packages/app/tests/integration/bug3-source-mode-writeback.test.ts
@@ -1,3 +1,4 @@
+
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
index 6fcdc23f2..4fc2c11f9 100644
--- a/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
+++ b/packages/app/tests/integration/indented-jsx-byte-sacred.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { normalizeBridge } from '@inkeep/open-knowledge-core';
import { updateYFragment } from '@tiptap/y-tiptap';
diff --git a/packages/app/tests/integration/interior-edit-freshness.test.ts b/packages/app/tests/integration/interior-edit-freshness.test.ts
index 40b5cdfd6..9f2f6feb6 100644
--- a/packages/app/tests/integration/interior-edit-freshness.test.ts
+++ b/packages/app/tests/integration/interior-edit-freshness.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
index 93666af70..2a085742b 100644
--- a/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
+++ b/packages/app/tests/integration/keystroke-cadence-danger-space.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/producer-guard-wiring.test.ts b/packages/app/tests/integration/producer-guard-wiring.test.ts
index 867598d34..878d5196b 100644
--- a/packages/app/tests/integration/producer-guard-wiring.test.ts
+++ b/packages/app/tests/integration/producer-guard-wiring.test.ts
@@ -1,3 +1,4 @@
+
import { setTimeout as wait } from 'node:timers/promises';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
diff --git a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
index 0970ac12f..4ada3cf26 100644
--- a/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
+++ b/packages/app/tests/integration/qa-039-reconciliation-counters-http.test.ts
@@ -1,3 +1,4 @@
+
import { randomUUID } from 'node:crypto';
import { afterEach, describe, expect, test } from 'vitest';
import { agentWriteMd, createTestServer, type TestServer } from './test-harness';
diff --git a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
index b632185e1..cbe2b705f 100644
--- a/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
+++ b/packages/app/tests/integration/qa-045-restore-after-gc.test.ts
@@ -1,3 +1,4 @@
+
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
import { join } from 'node:path';
diff --git a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
index c530ce4ba..89bc9b4d9 100644
--- a/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
+++ b/packages/app/tests/integration/qa-050-rollback-undo-shipped-path.test.ts
@@ -1,3 +1,4 @@
+
import { randomUUID } from 'node:crypto';
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
import type * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-after-rollback.test.ts b/packages/app/tests/integration/undo-after-rollback.test.ts
index d3767adc9..a78aeb0e4 100644
--- a/packages/app/tests/integration/undo-after-rollback.test.ts
+++ b/packages/app/tests/integration/undo-after-rollback.test.ts
@@ -1,3 +1,4 @@
+
import { ROLLBACK_ORIGIN } from '@inkeep/open-knowledge-server';
import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import * as Y from 'yjs';
diff --git a/packages/app/tests/integration/undo-recycle-reset.test.ts b/packages/app/tests/integration/undo-recycle-reset.test.ts
index b076f955c..e7cc69c3f 100644
--- a/packages/app/tests/integration/undo-recycle-reset.test.ts
+++ b/packages/app/tests/integration/undo-recycle-reset.test.ts
@@ -1,3 +1,4 @@
+
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { setTimeout as wait } from 'node:timers/promises';
diff --git a/packages/app/tests/integration/undo-rederive-survival.test.ts b/packages/app/tests/integration/undo-rederive-survival.test.ts
index 7935e35f8..9ddcd0730 100644
--- a/packages/app/tests/integration/undo-rederive-survival.test.ts
+++ b/packages/app/tests/integration/undo-rederive-survival.test.ts
@@ -1,3 +1,4 @@
+
import { prependFrontmatter } from '@inkeep/open-knowledge-core';
import { Plugin, PluginKey } from '@tiptap/pm/state';
import { updateYFragment, yXmlFragmentToProseMirrorRootNode } from '@tiptap/y-tiptap';
diff --git a/packages/core/src/bridge/compose.ts b/packages/core/src/bridge/compose.ts
index f4cc8a286..2a597ec3d 100644
--- a/packages/core/src/bridge/compose.ts
+++ b/packages/core/src/bridge/compose.ts
@@ -1,3 +1,4 @@
+
import { prependFrontmatter, stripFrontmatter } from '../extensions/frontmatter.ts';
export type ComposeAdjustment = 'none' | 'body' | 'frontmatter' | 'unresolved';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index 8fb428b90..01ef76a9f 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,3 +1,4 @@
+
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
import { carriedEdgeEmpties, type DocEdgeEmpties } from '../markdown/doc-edge-blank-runs.ts';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index fc267cbea..fb0ba5a7c 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index bfd7e3109..fa3cfcd86 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,3 +1,4 @@
+
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 4d3250d3a..8be632ba4 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,3 +1,4 @@
+
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/server/src/timeline-query.test.ts b/packages/server/src/timeline-query.test.ts
index 3aed8c14f..cc71b727a 100644
--- a/packages/server/src/timeline-query.test.ts
+++ b/packages/server/src/timeline-query.test.ts
@@ -30,6 +30,64 @@ import {
} from './shadow-repo';
import { getDocumentHistory, getFolderTimeline, historyWalkCap } from './timeline-query';
+const CHAIN_PERF_SAMPLES = 3;
+const CHECKPOINT_PERF_SAMPLES = 3;
+
+type TimelineQueryRun = () => Promise<Awaited<ReturnType<typeof getDocumentHistory>>>;
+
+function median(runs: number[]): number {
+ const sorted = [...runs].sort((a, b) => a - b);
+ return sorted[Math.floor(sorted.length / 2)] ?? Number.NaN;
+}
+
+async function timeQuery(run: TimelineQueryRun): Promise<{ ms: number; total: number }> {
+ const t0 = performance.now();
+ const result = await run();
+ return { ms: performance.now() - t0, total: result.total };
+}
+
+async function sampleChainWalkCost(
+ withRenameHistory: TimelineQueryRun,
+ withoutRenameHistory: TimelineQueryRun,
+ samples: number,
+ fixtureCommitCounts: { reachingWholeChain: number; reachingCurrentNameOnly: number },
+): Promise<{ ratios: number[]; withMs: number[]; withoutMs: number[] }> {
+ const { reachingWholeChain, reachingCurrentNameOnly } = fixtureCommitCounts;
+ const expectTotals = (label: string, run: { total: number }, expected: number): void => {
+ expect(
+ run.total,
+ `${label}: matched ${run.total} commits where this fixture builds exactly ${expected} that ` +
+ 'the query must reach. The fixture dates every commit, so this count is fixed by how many ' +
+ 'commits it writes and not by how fast the host wrote them. getDocumentHistory swallows a ' +
+ 'failed predecessor step and an outright error, and both make the with-chain arm cheaper ' +
+ 'without throwing, so an arm that walked less of the chain must not be priced as if it ' +
+ 'had run',
+ ).toBe(expected);
+ };
+
+ const warmWith = await timeQuery(withRenameHistory);
+ const warmWithout = await timeQuery(withoutRenameHistory);
+ expectTotals('warm-up, with-chain', warmWith, reachingWholeChain);
+ expectTotals('warm-up, no-chain', warmWithout, reachingCurrentNameOnly);
+
+ const ratios: number[] = [];
+ const withMs: number[] = [];
+ const withoutMs: number[] = [];
+ for (let i = 0; i < samples; i++) {
+ const chainFirst = i % 2 === 0;
+ const first = await timeQuery(chainFirst ? withRenameHistory : withoutRenameHistory);
+ const second = await timeQuery(chainFirst ? withoutRenameHistory : withRenameHistory);
+ const w = chainFirst ? first : second;
+ const b = chainFirst ? second : first;
+ expectTotals(`sample ${i}, with-chain`, w, reachingWholeChain);
+ expectTotals(`sample ${i}, no-chain`, b, reachingCurrentNameOnly);
+ withMs.push(w.ms);
+ withoutMs.push(b.ms);
+ ratios.push(w.ms / b.ms);
+ }
+ return { ratios, withMs, withoutMs };
+}
+
let tmpDir: string;
beforeEach(async () => {
@@ -662,9 +720,11 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {
expect(aShas).toContain(newASha);
}, 15_000);
- test('perf: chain depth 5 query completes in bounded latency', async () => {
+ test('perf: chain depth 5 walk reaches every epoch, and records its relative cost', async () => {
const { contentDir, shadow } = await setup();
+ const { cw, sv } = datedCommits(shadow);
const names = ['a', 'b', 'c', 'd', 'e', 'f'];
+ const commitsPerEpoch = 2;
const index = createEmptyIndex();
let prevName: string | null = null;
for (const name of names) {
@@ -674,7 +734,7 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {
} catch {}
}
writeFileSync(resolve(contentDir, `${name}.md`), `# ${name}\n`);
- const sha = await commitWip(shadow, human, 'content/docs', `WIP: ${name}`);
+ const sha = await cw(`WIP: ${name}`);
if (prevName) {
appendRenameLogEntry(
shadow.gitDir,
@@ -682,21 +742,44 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {
index,
);
}
- await saveVersion(shadow, 'content/docs', [human]);
+ await sv();
prevName = name;
}
setRenameLogIndex(shadow.gitDir, index);
- const t0 = performance.now();
- const result = await getDocumentHistory(shadow, { docName: 'f' }, 'content/docs');
- const elapsed = performance.now() - t0;
- expect(result.entries.length).toBeGreaterThan(0);
- expect(elapsed).toBeLessThan(2_000);
+ const noRenameHistory = createEmptyIndex();
+ const withRenameHistory = () => getDocumentHistory(shadow, { docName: 'f' }, 'content/docs');
+ const withoutRenameHistory = () =>
+ getDocumentHistory(shadow, { docName: 'f' }, 'content/docs', {
+ renameLogIndex: noRenameHistory,
+ });
+
+ const { ratios, withMs, withoutMs } = await sampleChainWalkCost(
+ withRenameHistory,
+ withoutRenameHistory,
+ CHAIN_PERF_SAMPLES,
+ {
+ reachingWholeChain: names.length * commitsPerEpoch,
+ reachingCurrentNameOnly: commitsPerEpoch,
+ },
+ );
+ const ratio = median(ratios);
+ const withMedian = median(withMs);
+ const withoutMedian = median(withoutMs);
+
+ console.log(
+ `[perf] chain depth 5, ${CHAIN_PERF_SAMPLES} pairs: median per-pair ratio ` +
+ `${ratio.toFixed(2)}x; arm medians with-chain ${withMedian.toFixed(0)}ms, no-chain ` +
+ `${withoutMedian.toFixed(0)}ms. All three are observations, not assertions. At this depth and without checkpoints the per-query fixed cost is too large a share of both arms for the ratio to discriminate a regression, so asserting it here would be vacuous. What this test pins is the fixture-anchored commit count above.`,
+ );
}, 30_000);
- test('perf: chain depth 5 + 100 checkpoints stays within NFR target', async () => {
+ test('perf: chain depth 5 + ~100 checkpoints walk reaches every epoch, and records its relative cost', async () => {
const { contentDir, shadow } = await setup();
+ const { cw, sv } = datedCommits(shadow);
const names = ['a', 'b', 'c', 'd', 'e', 'f'];
+ const revisionsPerEpoch = 17;
+ const commitsPerEpoch = 1 + revisionsPerEpoch * 2;
const index = createEmptyIndex();
let prevName: string | null = null;
for (const name of names) {
@@ -706,7 +789,7 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {
} catch {}
}
writeFileSync(resolve(contentDir, `${name}.md`), `# ${name} v0\n`);
- const renameSha = await commitWip(shadow, human, 'content/docs', `WIP: ${name} v0`);
+ const renameSha = await cw(`WIP: ${name} v0`);
if (prevName) {
appendRenameLogEntry(
shadow.gitDir,
@@ -714,33 +797,46 @@ describe('getDocumentHistory — rename-history mitigation (US-004)', () => {
index,
);
}
- for (let i = 1; i <= 17; i++) {
+ for (let i = 1; i <= revisionsPerEpoch; i++) {
writeFileSync(resolve(contentDir, `${name}.md`), `# ${name} v${i}\n`);
- await commitWip(shadow, human, 'content/docs', `WIP: ${name} v${i}`);
- await saveVersion(shadow, 'content/docs', [human]);
+ await cw(`WIP: ${name} v${i}`);
+ await sv();
}
prevName = name;
}
setRenameLogIndex(shadow.gitDir, index);
- await getDocumentHistory(shadow, { docName: 'f' }, 'content/docs');
+ const noRenameHistory = createEmptyIndex();
+ const withRenameHistory = () => getDocumentHistory(shadow, { docName: 'f' }, 'content/docs');
+ const withoutRenameHistory = () =>
+ getDocumentHistory(shadow, { docName: 'f' }, 'content/docs', {
+ renameLogIndex: noRenameHistory,
+ });
- const runs: number[] = [];
- for (let i = 0; i < 3; i++) {
- const t0 = performance.now();
- const result = await getDocumentHistory(shadow, { docName: 'f' }, 'content/docs');
- runs.push(performance.now() - t0);
- expect(result.entries.length).toBeGreaterThan(0);
- }
- runs.sort((a, b) => a - b);
- const median = runs[1] ?? runs[0] ?? 0;
+ const { ratios, withMs, withoutMs } = await sampleChainWalkCost(
+ withRenameHistory,
+ withoutRenameHistory,
+ CHECKPOINT_PERF_SAMPLES,
+ {
+ reachingWholeChain: names.length * commitsPerEpoch,
+ reachingCurrentNameOnly: commitsPerEpoch,
+ },
+ );
+ const ratio = median(ratios);
+ const withMedian = median(withMs);
+ const withoutMedian = median(withoutMs);
console.log(
- `[perf] chain depth 5 + ~100 checkpoints median: ${median.toFixed(1)}ms ` +
- `(NFR ≤ 200ms; runs: ${runs.map((r) => r.toFixed(0)).join('ms, ')}ms)`,
+ `[perf] chain depth 5 + ~100 checkpoints, ${CHECKPOINT_PERF_SAMPLES} pairs: median per-pair ` +
+ `ratio ${ratio.toFixed(2)}x; arm medians with-chain ${withMedian.toFixed(0)}ms, no-chain ` +
+ `${withoutMedian.toFixed(0)}ms. All three are observations, not assertions. A ceiling of ` +
+ `${names.length}x, the number of name epochs the chain spans, was measured against a ` +
+ 'quadratic mutation of the chain walk and separated it from healthy code in only two of ' +
+ 'four runs, so at this depth the per-query fixed cost both arms pay compresses the ratio ' +
+ 'too far for it to discriminate. What this test pins is the fixture-anchored commit count ' +
+ 'above. An executable owner for the read-path cost belongs in the variance-aware ' +
+ 'comparator, which this change did not adopt.',
);
-
- expect(median).toBeLessThan(1_000);
}, 180_000);
test('lazy-population window: empty-commitSha entry → chain truncates → behavior matches no-rename-history', async () => {