Skip to content

Commit 4a065c1

Browse files
authored
Make mounted REPL call-count baselines repeatable at 1% (#1543)
* perf(repl): reuse validated renderer bounds Recovered from correction-1540/correction.patch. Original: 14cf2bae385b83072d99eb1407f12e5ac88b2a3f. * test(repl): configure startup-only Todo refresh for mounted profiles Rebuilt e5ebb3b4c91f8ba23fc16ae7ae48655c3a8330c4 from its review transcript and archived workload documents. * test(profile): prepare the reading viewport with a resize Rebuilt ece3f0f493fa9d2681312f1a24b749620737b00e from the reviewed Markdown diff. * perf(repl): batch placement of late siblings Supersedes 8245eb670763e70079967cc02d27bcb4024f01b7 using its reviewed keyed reconciliation and tests, with one sibling pass per affected parent as modeled in artifacts/1530/batching-8245eb6. * test(profile): refresh mounted REPL call-count baselines Record the 13 typing, reading-scroll, and draft-scroll snapshots on Deno 2.9.7 Darwin arm64 at 1%. Verify ten fresh update-off runs per document and all three scratch workload controls. * fix(repl): type prepared sibling entries for Node Fixes #1543. Type the preparation array explicitly for the Node CI tsconfig. The emitted reconciler JavaScript is unchanged.
1 parent ef85097 commit 4a065c1

35 files changed

Lines changed: 666 additions & 339 deletions

‎examples/repl-bench/README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,12 @@ inherits nothing from the journey, including its testing session.
562562
body runs. A mounted launch answers `Terminal.Focus`, `Terminal.Type`,
563563
`Terminal.Key`, `Terminal.Resize`, and `Terminal.WaitForText` by text in the
564564
viewport or the `sidekick-composer` region. Every other component refuses. It
565-
runs the current build and takes none of the other launch options.
565+
runs the current build.
566+
567+
Inside a `<Test>`, a mounted launch can set `todoRefresh="startup-only"` to
568+
load the checklist at startup and omit periodic external-file refresh. Explicit
569+
reads and writes still use the current file. Omit the option for journeys that
570+
exercise external edits. PTY launches and launches outside `<Test>` refuse it.
566571

567572
Each Terminal hosts one active launch. The bench owns its driver, REPL
568573
process, attached Sidekick, and output capture. Its cleanup joins the child
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Test name="Todo refresh configuration validates before reserving the terminal" timeout="120s">
2+
<Terminal columns={160} rows={36}>
3+
<XMD.Repl mounted={true} todoRefresh="startup-only">
4+
<Terminal.WaitForText text="Ready for Entry 1" />
5+
<Try>
6+
<XMD.Repl todoRefresh="startup-only"><Fail message="started a PTY" /></XMD.Repl>
7+
<Catch as="error"><AssertStringIncludes actual={error.message} expected="only on mounted" /></Catch>
8+
</Try>
9+
<Try>
10+
<XMD.Repl mounted={true} todoRefresh="unknown"><Fail message="started with unknown mode" /></XMD.Repl>
11+
<Catch as="error"><AssertStringIncludes actual={error.message} expected="/todoRefresh" /></Catch>
12+
</Try>
13+
<Try>
14+
<XMD.Repl mounted={true} todoRefresh="startup-only" expectExit={true}><Fail message="started with PTY options" /></XMD.Repl>
15+
<Catch as="error"><AssertStringIncludes actual={error.message} expected="runs the current build" /></Catch>
16+
</Try>
17+
<Terminal.WaitForText text="Ready for Entry 1" />
18+
</XMD.Repl>
19+
<XMD.Repl mounted={true}>
20+
<Terminal.WaitForText text="Ready for Entry 1" />
21+
</XMD.Repl>
22+
</Terminal>
23+
</Test>

‎examples/repl-bench/lib/driver-mounted.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import {
1515
generateTypingDraft,
1616
generateTypingHistory,
1717
} from "../../../packages/cli/tests/support/typing-history.ts";
18+
import type { TodoRefreshSchedule } from "../../../packages/cli/src/repl/todo/service.ts";
1819
import type { Command, Region, Size } from "./protocol.ts";
1920

2021
export interface MountedOptions extends Size {
22+
readonly todoRefresh?: TodoRefreshSchedule;
2123
readonly draft?: { readonly lines: number };
2224
readonly history?: { readonly rounds: number; readonly linesPerRound: number };
2325
}
@@ -158,7 +160,10 @@ export function* connectMounted(
158160
const ready = withResolvers<ReplPage>();
159161
scope.run(function* () {
160162
try {
161-
const page = yield* useReplPage({ size: { columns: options.columns, rows: options.rows } });
163+
const page = yield* useReplPage({
164+
size: { columns: options.columns, rows: options.rows },
165+
todoRefresh: options.todoRefresh,
166+
});
162167
if (options.history !== undefined) {
163168
const { rounds, linesPerRound } = options.history;
164169
yield* generateTypingHistory(page, rounds, linesPerRound, true);

‎examples/repl-bench/plugin.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const bench = size.partial().extend({
125125
mount: z.array(z.string().min(1)).default([]),
126126
plugins: z.array(z.string().min(1)).default([]),
127127
mounted: z.boolean().default(false),
128+
todoRefresh: z.literal("startup-only").optional(),
128129
draft: z.object({ lines: z.int().positive() }).optional(),
129130
history: z.object({ rounds: z.int().positive(), linesPerRound: z.int().positive() }).optional(),
130131
allowAbsolute: z.boolean().default(false),
@@ -159,7 +160,6 @@ const XmdBuild: FunctionComponent = function* (props, invocation) {
159160
function* mountedRepl(
160161
wanted: z.infer<typeof bench>,
161162
enclosing: ReturnType<typeof createTerminal> | undefined,
162-
reservation: { dispatch?: Execute } | undefined,
163163
waitTimeout: number | undefined,
164164
) {
165165
if (
@@ -175,7 +175,7 @@ function* mountedRepl(
175175
(yield* Build.get()) !== undefined
176176
) {
177177
throw new Error(
178-
"A mounted <XMD.Repl> takes dimensions, waitTimeout, history and draft, and runs the current build.",
178+
"A mounted <XMD.Repl> takes dimensions, waitTimeout, history, draft and todoRefresh, and runs the current build.",
179179
);
180180
}
181181
const terminal =
@@ -184,12 +184,13 @@ function* mountedRepl(
184184
columns: wanted.columns ?? defaultSize.columns,
185185
rows: wanted.rows ?? defaultSize.rows,
186186
});
187-
const active = reservation ?? (yield* terminal.claim());
187+
const active = yield* terminal.claim();
188188
const { connectMounted } = yield* until(import("./lib/driver-mounted.ts"));
189189
active.dispatch = yield* connectMounted({
190190
...terminal.dimensions,
191191
history: wanted.history,
192192
draft: wanted.draft,
193+
todoRefresh: wanted.todoRefresh,
193194
});
194195
yield* ensure(() => {
195196
delete active.dispatch;
@@ -207,12 +208,15 @@ const XmdRepl: FunctionComponent = function* (props, invocation) {
207208
if (!invocation.hasContent()) {
208209
throw new Error("Use a paired <XMD.Repl>");
209210
}
211+
const wanted = bench.parse(props);
210212
const test = yield* Test.operations.testScope;
213+
if (wanted.todoRefresh !== undefined && (test === undefined || !wanted.mounted)) {
214+
throw new Error("todoRefresh is supported only on mounted <XMD.Repl> inside <Test>");
215+
}
211216
if (test === undefined && !(yield* EntryBench.expect())) {
212217
throw new Error("<XMD.Repl> needs an enclosing <Test> or a development REPL entry");
213218
}
214219
const directory = yield* cwd();
215-
const wanted = bench.parse(props);
216220
const build = yield* Build.get();
217221
if (
218222
test === undefined &&
@@ -239,14 +243,14 @@ const XmdRepl: FunctionComponent = function* (props, invocation) {
239243
if (enclosing !== undefined && (wanted.columns !== undefined || wanted.rows !== undefined)) {
240244
throw new Error("Set viewport dimensions on the enclosing <Terminal>");
241245
}
242-
const reservation = enclosing === undefined ? undefined : yield* enclosing.claim();
243246
const waitTimeout =
244247
wanted.waitTimeout === undefined
245248
? undefined
246249
: parseDuration(wanted.waitTimeout, "<XMD.Repl waitTimeout>");
247250
if (wanted.mounted) {
248-
return yield* mountedRepl(wanted, enclosing, reservation, waitTimeout);
251+
return yield* mountedRepl(wanted, enclosing, waitTimeout);
249252
}
253+
const reservation = enclosing === undefined ? undefined : yield* enclosing.claim();
250254
const captured = (yield* hasCapture("resume")) ? yield* capture("resume") : undefined;
251255
const allocateTestHome = function* () {
252256
const resumes = (yield* Resumes.get()) ?? (yield* Resumes.set(new WeakMap()));
@@ -463,6 +467,7 @@ const replLaunch = {
463467
mount: strings,
464468
plugins: strings,
465469
mounted: boolean,
470+
todoRefresh: { type: "string", enum: ["startup-only"] },
466471
draft: {
467472
type: "object",
468473
properties: { lines: integer },

‎examples/xmd-profile/README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,22 @@ typing comparison in ReplBench still supplies milliseconds.
181181

182182
[scrolling.md](baselines/scrolling.md) measures entry-reading wheel bursts at sparse,
183183
full, long-history and long-entry sizes, plus spaced notches at the full size.
184+
After history setup, each case resizes from 200×52 to 199×52 and back before
185+
positioning the reading. This clears the layout engine's accumulated element
186+
IDs before the capture. The wheel exercise runs at 200×52 from the verified
187+
starting window.
188+
184189
[scrolling-draft.md](baselines/scrolling-draft.md) measures arrow keys with a still
185190
window, a window moved by warm-up, and a longer draft. Its `draft-wheel` case
186191
measures bursts that move the draft window three rows per notch without moving
187192
the caret. It records
188193
[scrolling-draft-wheel.baseline.md](baselines/scrolling-draft-wheel.baseline.md).
189194

195+
The three mounted baseline documents use `todoRefresh="startup-only"`. Each
196+
launch loads its checklist and supports explicit reads and writes. The capture
197+
exercises typing or scrolling without periodic external-file refresh. Record one
198+
capture per case and compare it at the default 1% tolerance.
199+
190200
## Profile a REPL session
191201

192202
A REPL launched with the plugin keeps a capture open across entries, so the

‎examples/xmd-profile/baselines/scrolling-draft-caret-moving-long.baseline.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ The other layers row is recorded for context and never fails the comparison.
1818

1919
| Measure | Value |
2020
| --- | ---: |
21-
| calls: total | 24,204,839 |
22-
| calls: npm @xterm/headless | 14,068,491 |
23-
| calls: xmd cli | 5,915,172 |
24-
| calls: npm @termless/xtermjs | 2,058,270 |
25-
| calls: deno runtime | 971,158 |
26-
| calls: effection | 900,332 |
27-
| calls: effectionx | 118,137 |
28-
| calls: xmd core | 99,036 |
21+
| calls: total | 24,247,379 |
22+
| calls: npm @xterm/headless | 15,067,461 |
23+
| calls: xmd cli | 4,933,322 |
24+
| calls: npm @termless/xtermjs | 2,185,110 |
25+
| calls: deno runtime | 913,718 |
26+
| calls: effection | 878,914 |
27+
| calls: effectionx | 108,465 |
28+
| calls: xmd core | 95,273 |
2929
| calls: npm @secretlint/core | 30,120 |
30-
| calls: other layers | 44,123 |
30+
| calls: other layers | 34,996 |
3131

3232
```json
3333
{
@@ -39,43 +39,43 @@ The other layers row is recorded for context and never fails the comparison.
3939
"measures": [
4040
{
4141
"name": "calls: total",
42-
"value": 24204839
42+
"value": 24247379
4343
},
4444
{
4545
"name": "calls: npm @xterm/headless",
46-
"value": 14068491
46+
"value": 15067461
4747
},
4848
{
4949
"name": "calls: xmd cli",
50-
"value": 5915172
50+
"value": 4933322
5151
},
5252
{
5353
"name": "calls: npm @termless/xtermjs",
54-
"value": 2058270
54+
"value": 2185110
5555
},
5656
{
5757
"name": "calls: deno runtime",
58-
"value": 971158
58+
"value": 913718
5959
},
6060
{
6161
"name": "calls: effection",
62-
"value": 900332
62+
"value": 878914
6363
},
6464
{
6565
"name": "calls: effectionx",
66-
"value": 118137
66+
"value": 108465
6767
},
6868
{
6969
"name": "calls: xmd core",
70-
"value": 99036
70+
"value": 95273
7171
},
7272
{
7373
"name": "calls: npm @secretlint/core",
7474
"value": 30120
7575
},
7676
{
7777
"name": "calls: other layers",
78-
"value": 44123
78+
"value": 34996
7979
}
8080
]
8181
}

‎examples/xmd-profile/baselines/scrolling-draft-caret-moving.baseline.md‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ The other layers row is recorded for context and never fails the comparison.
1818

1919
| Measure | Value |
2020
| --- | ---: |
21-
| calls: total | 22,606,052 |
22-
| calls: npm @xterm/headless | 14,073,955 |
23-
| calls: xmd cli | 4,791,521 |
24-
| calls: npm @termless/xtermjs | 2,058,270 |
25-
| calls: effection | 895,282 |
26-
| calls: deno runtime | 493,920 |
27-
| calls: effectionx | 117,989 |
28-
| calls: xmd core | 99,006 |
21+
| calls: total | 22,655,266 |
22+
| calls: npm @xterm/headless | 15,072,925 |
23+
| calls: xmd cli | 3,809,884 |
24+
| calls: npm @termless/xtermjs | 2,185,110 |
25+
| calls: effection | 878,914 |
26+
| calls: deno runtime | 437,590 |
27+
| calls: effectionx | 108,465 |
28+
| calls: xmd core | 95,243 |
2929
| calls: npm @secretlint/core | 30,120 |
30-
| calls: other layers | 45,989 |
30+
| calls: other layers | 37,015 |
3131

3232
```json
3333
{
@@ -39,43 +39,43 @@ The other layers row is recorded for context and never fails the comparison.
3939
"measures": [
4040
{
4141
"name": "calls: total",
42-
"value": 22606052
42+
"value": 22655266
4343
},
4444
{
4545
"name": "calls: npm @xterm/headless",
46-
"value": 14073955
46+
"value": 15072925
4747
},
4848
{
4949
"name": "calls: xmd cli",
50-
"value": 4791521
50+
"value": 3809884
5151
},
5252
{
5353
"name": "calls: npm @termless/xtermjs",
54-
"value": 2058270
54+
"value": 2185110
5555
},
5656
{
5757
"name": "calls: effection",
58-
"value": 895282
58+
"value": 878914
5959
},
6060
{
6161
"name": "calls: deno runtime",
62-
"value": 493920
62+
"value": 437590
6363
},
6464
{
6565
"name": "calls: effectionx",
66-
"value": 117989
66+
"value": 108465
6767
},
6868
{
6969
"name": "calls: xmd core",
70-
"value": 99006
70+
"value": 95243
7171
},
7272
{
7373
"name": "calls: npm @secretlint/core",
7474
"value": 30120
7575
},
7676
{
7777
"name": "calls: other layers",
78-
"value": 45989
78+
"value": 37015
7979
}
8080
]
8181
}

0 commit comments

Comments
 (0)