70160
Ce
cel-tui / files
cel-tui / benchmarks / real-world.bench.ts
5.9 KB
1/** 2 * Benchmark: real-world synthetic app shapes. 3 * 4 * These fixtures mimic mini-coder / mini-coder-next node tree shapes without 5 * importing those apps: long unvirtualized conversations, virtualized message 6 * windows, syntax-highlight-like blocks, and wide wrapping token rows. 7 */ 8 9import { CellBuffer, emitBuffer, measureContentHeight } from "@cel-tui/core"; 10import { bench, group, run } from "mitata"; 11import { emitDiff } from "../packages/core/src/emitter.js"; 12import { layout } from "../packages/core/src/layout.js"; 13import { paint } from "../packages/core/src/paint.js"; 14import { clearTextMeasurementCaches } from "../packages/core/src/text-layout.js"; 15import { clearVisibleWidthCache } from "../packages/core/src/width.js"; 16import { 17 hstackTokenRow, 18 miniCoderNextConversationTree, 19 miniCoderNextMeasureNodes, 20 miniCoderVirtualizedConversationTree, 21} from "./helpers.js"; 22 23const W = 120; 24const H = 40; 25 26function clearMeasurementCaches(): void { 27 clearTextMeasurementCaches(); 28 clearVisibleWidthCache(); 29} 30 31// --- mini-coder-next: unvirtualized long conversation layout --- 32 33group("real-world: mini-coder-next long conversation layout", () => { 34 const t100 = miniCoderNextConversationTree(100); 35 const t500 = miniCoderNextConversationTree(500); 36 const t1000 = miniCoderNextConversationTree(1000); 37 38 bench("100 messages (120×40)", () => { 39 layout(t100, W, H); 40 }); 41 42 bench("500 messages (120×40)", () => { 43 layout(t500, W, H); 44 }); 45 46 bench("1000 messages (120×40)", () => { 47 layout(t1000, W, H); 48 }); 49}); 50 51// --- mini-coder-next: cold-cache first render/layout --- 52 53group("real-world: mini-coder-next cold first render", () => { 54 const t100 = miniCoderNextConversationTree(100); 55 const t500 = miniCoderNextConversationTree(500); 56 const t1000 = miniCoderNextConversationTree(1000); 57 const measureNodes = miniCoderNextMeasureNodes(250); 58 59 bench("cold layout 100 messages (120×40)", () => { 60 clearMeasurementCaches(); 61 layout(t100, W, H); 62 }); 63 64 bench("cold layout 500 messages (120×40)", () => { 65 clearMeasurementCaches(); 66 layout(t500, W, H); 67 }); 68 69 bench("cold layout 1000 messages (120×40)", () => { 70 clearMeasurementCaches(); 71 layout(t1000, W, H); 72 }); 73 74 bench("cold full render 250 messages (120×40)", () => { 75 clearMeasurementCaches(); 76 const tree = miniCoderNextConversationTree(250); 77 const l = layout(tree, W, H); 78 const buf = new CellBuffer(W, H); 79 paint(l, buf); 80 emitBuffer(buf); 81 }); 82 83 bench("cold measure content height 250 nodes at width 118", () => { 84 clearMeasurementCaches(); 85 let total = 0; 86 for (const node of measureNodes) { 87 total += measureContentHeight(node, { width: 118 }); 88 } 89 return total; 90 }); 91}); 92 93// --- mini-coder-next: paint pre-laid unvirtualized conversations --- 94 95group("real-world: mini-coder-next long conversation paint", () => { 96 const l500 = layout(miniCoderNextConversationTree(500), W, H); 97 const l1000 = layout(miniCoderNextConversationTree(1000), W, H); 98 99 bench("500 messages (120×40)", () => { 100 const buf = new CellBuffer(W, H); 101 paint(l500, buf); 102 }); 103 104 bench("1000 messages (120×40)", () => { 105 const buf = new CellBuffer(W, H); 106 paint(l1000, buf); 107 }); 108}); 109 110// --- mini-coder-next: full render and diff render including tree construction --- 111 112group("real-world: mini-coder-next e2e", () => { 113 const prevTree = miniCoderNextConversationTree(250); 114 const prevLayout = layout(prevTree, W, H); 115 const prevBuf = new CellBuffer(W, H); 116 paint(prevLayout, prevBuf); 117 118 bench("full render 250 messages (120×40)", () => { 119 const tree = miniCoderNextConversationTree(250); 120 const l = layout(tree, W, H); 121 const buf = new CellBuffer(W, H); 122 paint(l, buf); 123 emitBuffer(buf); 124 }); 125 126 bench("diff render 250 → 251 messages (120×40)", () => { 127 const tree = miniCoderNextConversationTree(251); 128 const l = layout(tree, W, H); 129 const buf = new CellBuffer(W, H); 130 paint(l, buf); 131 emitDiff(prevBuf, buf); 132 }); 133}); 134 135// --- HStack token-list stress tests --- 136 137group("real-world: hstack token lists", () => { 138 const r100 = hstackTokenRow(100); 139 const r500 = hstackTokenRow(500); 140 const r1000 = hstackTokenRow(1000); 141 const l100 = layout(r100, W, H); 142 const l500 = layout(r500, W, H); 143 const l1000 = layout(r1000, W, H); 144 145 bench("layout 100 tokens (120×40)", () => { 146 layout(r100, W, H); 147 }); 148 149 bench("layout 500 tokens (120×40)", () => { 150 layout(r500, W, H); 151 }); 152 153 bench("layout 1000 tokens (120×40)", () => { 154 layout(r1000, W, H); 155 }); 156 157 bench("paint 100 tokens (120×40)", () => { 158 const buf = new CellBuffer(W, H); 159 paint(l100, buf); 160 }); 161 162 bench("paint 500 tokens (120×40)", () => { 163 const buf = new CellBuffer(W, H); 164 paint(l500, buf); 165 }); 166 167 bench("paint 1000 tokens (120×40)", () => { 168 const buf = new CellBuffer(W, H); 169 paint(l1000, buf); 170 }); 171}); 172 173// --- mini-coder: virtualized conversation layout/paint --- 174 175group("real-world: mini-coder virtualized conversation", () => { 176 const v1000 = miniCoderVirtualizedConversationTree(1000, 40); 177 const v5000 = miniCoderVirtualizedConversationTree(5000, 40); 178 const l1000 = layout(v1000, W, H); 179 const l5000 = layout(v5000, W, H); 180 181 bench("layout total 1000 / visible 40 (120×40)", () => { 182 layout(v1000, W, H); 183 }); 184 185 bench("layout total 5000 / visible 40 (120×40)", () => { 186 layout(v5000, W, H); 187 }); 188 189 bench("paint total 1000 / visible 40 (120×40)", () => { 190 const buf = new CellBuffer(W, H); 191 paint(l1000, buf); 192 }); 193 194 bench("paint total 5000 / visible 40 (120×40)", () => { 195 const buf = new CellBuffer(W, H); 196 paint(l5000, buf); 197 }); 198}); 199 200// --- Content height measurement for prebuilt message nodes --- 201 202group("real-world: content height measurement", () => { 203 const nodes = miniCoderNextMeasureNodes(250); 204 205 bench("250 representative message nodes at width 118", () => { 206 let total = 0; 207 for (const node of nodes) { 208 total += measureContentHeight(node, { width: 118 }); 209 } 210 return total; 211 }); 212}); 213 214await run();