Files
oh-my-pi/packages/coding-agent/bench/rendering.ts
T
can1357 8ef11355e7 perf(tui,natives): added native text utilities with JS fast path for short strings
- Added native text utilities in pi-natives (visible width, truncation, slicing, segment extraction)
- Wired pi-tui to use native implementations with short-string JS fast path
- Optimized key matching via cached parsed key ids
- Refactored visual truncation to reuse Text instances
- Reduced theme color lookups by switching from Map to plain records
- Regenerated WASM artifacts

Benchmarks (after vs before, lower is better):
- truncateToWidth/ansi: 20.37ms vs 38.13ms (2000 iters)
- sliceWithWidth/ansi: 5.12ms vs 20.39ms
- extractSegments/ansi: 8.92ms vs 27.60ms
- truncateToVisualLines: 3.51ms vs 411.55ms (500 iters)
- visibleWidth/ansi: 0.24ms vs 0.31ms
2026-01-29 10:47:55 +01:00

42 lines
1.3 KiB
TypeScript

import { initTheme } from "../src/modes/theme/theme";
import { truncateToVisualLines } from "../src/modes/components/visual-truncate";
import { WelcomeComponent } from "../src/modes/components/welcome";
const ITERATIONS = 500;
const WIDTH = 100;
const longText = Array.from({ length: 200 })
.map((_, i) => `Line ${i + 1}: \x1b[32mcolored content\x1b[0m with emojis 🚀✨ and extra padding`)
.join("\n");
function bench(name: string, fn: () => void): number {
const start = performance.now();
for (let i = 0; i < ITERATIONS; i++) {
fn();
}
const elapsed = performance.now() - start;
const perOp = (elapsed / ITERATIONS).toFixed(4);
console.log(`${name}: ${elapsed.toFixed(2)}ms total (${perOp}ms/op)`);
return elapsed;
}
await initTheme("dark");
console.log(`Rendering benchmark (${ITERATIONS} iterations)\n`);
bench("truncateToVisualLines", () => {
truncateToVisualLines(longText, 20, WIDTH, 1);
});
const welcome = new WelcomeComponent("8.12.3", "claude-3.7", "anthropic", [
{ name: "Test session", timeAgo: "2m" },
{ name: "Another session", timeAgo: "1h" },
], [
{ name: "tsserver", status: "ready", fileTypes: ["ts", "tsx", "js"] },
{ name: "rust-analyzer", status: "connecting", fileTypes: ["rs"] },
]);
bench("WelcomeComponent.render", () => {
welcome.render(WIDTH);
});