Skip to content

Commit 44fbdd0

Browse files
yyq1025claude
andcommitted
markdown: drop dev-only tokenize/stats instrumentation
The onTokenizeMs + onStats probes — and the ChunkStats apparatus (per-delta lex timing + prefix-diff bookkeeping in useMarkdownBlocks) that fed them — only ever drove the /dev/chunked-markdown spike screen. That screen's renderer has since shipped into the production transcript path, leaving the probes as dead instrumentation threaded through production components. Remove the probes, the unused ChunkStats type, the spike screen, and its dev-menu/route registrations. Rendering behavior is unchanged: stability comes from positional keys + per-segment `raw` memo, not the removed stats. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 84ca2a9 commit 44fbdd0

7 files changed

Lines changed: 14 additions & 262 deletions

File tree

packages/app/src/app/(main)/_layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export default function MainLayout() {
6868
/>
6969
{/* Dev probe pages — keep as standard pushes, no modal. */}
7070
<Stack.Screen name="dev/keyboard-extender" />
71-
<Stack.Screen name="dev/chunked-markdown" />
7271
</Stack.Protected>
7372
</Stack>
7473
);

packages/app/src/app/(main)/dev/chunked-markdown.tsx

Lines changed: 0 additions & 195 deletions
This file was deleted.

packages/app/src/app/(main)/settings/index.ios.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ export default function SettingsIndexScreen() {
129129
label="KeyboardExtender spike"
130130
onPress={() => router.push("/dev/keyboard-extender")}
131131
/>
132-
<DisclosureRow
133-
label="Chunked markdown spike"
134-
onPress={() => router.push("/dev/chunked-markdown")}
135-
/>
136132
<Button
137133
label="Clear last cwd (test placeholder)"
138134
onPress={onClearLastCwd}

packages/app/src/lib/markdown/chunked-markdown.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
LIGHT_PALETTE,
1717
} from "./chat-markdown";
1818
import { useCodeTokens } from "./code-highlighter";
19-
import type { ChunkStats } from "./markdown-chunking";
2019
import { type MarkdownSegment, useMarkdownBlocks } from "./markdown-chunking";
2120
import { useRemend } from "./remend";
2221

@@ -32,8 +31,8 @@ import { useRemend } from "./remend";
3231
* re-tokenize per delta (~1-3.5ms measured on device for typical
3332
* blocks) + per-line memo keyed on token content, so settled lines
3433
* skip reconciliation and only the streaming line re-renders.
35-
* - Prefix-diff in useMarkdownBlocks guarantees completed segments
36-
* never re-render while the tail streams.
34+
* - Positional keys + per-segment `raw` memo keep completed segments
35+
* from re-rendering while the tail streams.
3736
*
3837
* The code container is `TextInput multiline editable={false}` — a real
3938
* UITextView, which gives PARTIAL selection with handles (RN iOS <Text
@@ -115,17 +114,15 @@ const TokenLine = memo(
115114
const CodeBlockSegment = memo(function CodeBlockSegment({
116115
lang,
117116
code,
118-
onTokenizeMs,
119117
}: {
120118
lang: string;
121119
code: string;
122-
onTokenizeMs?: (ms: number) => void;
123120
}) {
124121
const scheme = useColorScheme() === "dark" ? "dark" : "light";
125122
const palette = scheme === "dark" ? DARK_PALETTE : LIGHT_PALETTE;
126123
// Sync tokenize — see useCodeTokens for why (drawer-settle gate keeps
127124
// mount bursts out of animation windows). null → plain, same metrics.
128-
const lines = useCodeTokens(code, lang, scheme, onTokenizeMs);
125+
const lines = useCodeTokens(code, lang, scheme);
129126

130127
return (
131128
<View
@@ -176,23 +173,13 @@ const CodeBlockSegment = memo(function CodeBlockSegment({
176173
export function ChunkedMarkdown({
177174
markdown,
178175
streamDone,
179-
onStats,
180-
onTokenizeMs,
181176
}: {
182177
markdown: string;
183178
/** No settle signal available? Pass `true` — exact parity with
184179
* whole-message ChatMarkdown (no remend, EOF fences counted closed). */
185180
streamDone: boolean;
186-
/** Dev instrumentation. Called inline during render with the latest
187-
* chunk stats — consumers must only write to a ref (no setState). */
188-
onStats?: (stats: ChunkStats) => void;
189-
/** Dev instrumentation. Per-tokenize timing from code blocks (ref-write
190-
* only, same rule). Must be referentially stable or the CodeBlock memo
191-
* breaks. */
192-
onTokenizeMs?: (ms: number) => void;
193181
}) {
194-
const { segments, stats } = useMarkdownBlocks(markdown, streamDone);
195-
onStats?.(stats);
182+
const segments = useMarkdownBlocks(markdown, streamDone);
196183

197184
const lastIndex = segments.length - 1;
198185
return (
@@ -203,12 +190,7 @@ export function ChunkedMarkdown({
203190
{segments.map((seg: MarkdownSegment, i: number) => {
204191
if (seg.kind === "code") {
205192
return (
206-
<CodeBlockSegment
207-
key={seg.key}
208-
lang={seg.lang}
209-
code={seg.code}
210-
onTokenizeMs={onTokenizeMs}
211-
/>
193+
<CodeBlockSegment key={seg.key} lang={seg.lang} code={seg.code} />
212194
);
213195
}
214196
// Tail run streams → remend; completed runs are frozen + memo'd.

packages/app/src/lib/markdown/code-highlighter.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,11 @@ export function useCodeTokens(
222222
code: string,
223223
infoString: string,
224224
scheme: "light" | "dark",
225-
onTokenizeMs?: (ms: number) => void,
226225
): TokenLines | null {
227226
const hl = useHighlighter();
228227
const langId = resolveLang(infoString);
229228
return useMemo(() => {
230229
if (hl === null || langId === null) return null;
231-
const t0 = performance.now();
232-
const lines = tokenizeCode(hl, code, langId, scheme);
233-
onTokenizeMs?.(performance.now() - t0);
234-
return lines;
235-
}, [hl, langId, code, scheme, onTokenizeMs]);
230+
return tokenizeCode(hl, code, langId, scheme);
231+
}, [hl, langId, code, scheme]);
236232
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export type { ChatMarkdownProps } from "./chat-markdown";
22
export { ChatMarkdown } from "./chat-markdown";
33
export { ChunkedMarkdown } from "./chunked-markdown";
4-
export type { ChunkStats, MarkdownSegment } from "./markdown-chunking";
4+
export type { MarkdownSegment } from "./markdown-chunking";

packages/app/src/lib/markdown/markdown-chunking.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Token, Tokens } from "marked";
22
import { lexer } from "marked";
3-
import { useMemo, useRef } from "react";
3+
import { useMemo } from "react";
44

55
/**
66
* Chunked markdown for the native transcript
@@ -45,13 +45,6 @@ export type MarkdownSegment =
4545
closed: boolean;
4646
};
4747

48-
export interface ChunkStats {
49-
lexMs: number;
50-
segmentCount: number;
51-
/** First segment index whose raw changed vs the previous call (-1 = none). */
52-
firstChangedIndex: number;
53-
}
54-
5548
/** Fence closer must sit on its own line — `foo\`\`\`` inside content is
5649
* NOT a closer. Unclosed fences swallow to EOF (CommonMark), so only the
5750
* LAST segment can ever be open. */
@@ -232,28 +225,9 @@ export function chunkMarkdown(
232225
export function useMarkdownBlocks(
233226
markdown: string,
234227
streamDone: boolean,
235-
): { segments: MarkdownSegment[]; stats: ChunkStats } {
236-
const prevRef = useRef<MarkdownSegment[]>([]);
237-
return useMemo(() => {
238-
const t0 = performance.now();
239-
const segments = chunkMarkdown(markdown, streamDone);
240-
const lexMs = performance.now() - t0;
241-
242-
const prev = prevRef.current;
243-
let firstChangedIndex = -1;
244-
const max = Math.max(segments.length, prev.length);
245-
for (let i = 0; i < max; i++) {
246-
const a = segments[i];
247-
const b = prev[i];
248-
if (!a || !b || a.raw !== b.raw || a.kind !== b.kind) {
249-
firstChangedIndex = i;
250-
break;
251-
}
252-
}
253-
prevRef.current = segments;
254-
return {
255-
segments,
256-
stats: { lexMs, segmentCount: segments.length, firstChangedIndex },
257-
};
258-
}, [markdown, streamDone]);
228+
): MarkdownSegment[] {
229+
return useMemo(
230+
() => chunkMarkdown(markdown, streamDone),
231+
[markdown, streamDone],
232+
);
259233
}

0 commit comments

Comments
 (0)