The WASM scanner could fill its fixed 4096-op buffer on large inputs (e.g. 5MB of newlines or OSC traffic) and previously failed or appeared hung. ESC op coalescing also corrupted the lengths field used for dispatch, causing millions of redundant handler invocations on OSC benchmark data. WASM scanner (parser.c / parser.h): - Add scan_offset to ParserScanHeader; scan(offset, length) resumes after a partial fill instead of returning -1 for the whole buffer. - Return early from scan when the op buffer is full; all emit sites use emit_or_stop() so scan_offset records where to continue. - Coalesce consecutive OP_EXECUTE and OP_ESC ops with the same code/ident; lengths holds repeat count, starts holds the input index for ESC. - Keep CSI/DCS hook layout unchanged (lengths = final byte index, starts = param arena offset). TypeScript dispatch (EscapeSequenceParserWasm.ts): - Drive parsing via runWasmScanChunks(): scan a slice, dispatch ops, advance inputOffset to nextOffset until the chunk is consumed. - Fix ESC dispatch: chunkPos uses starts (input index); escCount uses lengths (repeat count). Avoid treating the CSI-style final-byte index as a loop bound. - Throw if nextOffset does not advance to catch stuck scans. EscapeSequenceParser.ts: - Extend _scanCache for chunked scan state; reset() clears inputOffset and cached scan data so later parses are not skipped. Benchmarks: - Import compiled modules from ../../out/common and ../../out/browser so npm run benchmark works without NODE_PATH after path-mapping removal. - Update benchmark skill notes accordingly. Build: - build_parser_wasm.sh selects a clang with wasm32 support (Homebrew LLVM on macOS when Xcode clang lacks the target). Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.2 KiB
TypeScript
69 lines
2.2 KiB
TypeScript
/**
|
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import { perfContext, before, ThroughputRuntimeCase } from 'xterm-benchmark';
|
|
|
|
import { spawn } from 'node-pty';
|
|
import { Utf8ToUtf32, stringFromCodePoint } from '../../out/common/input/TextDecoder';
|
|
import { CoreBrowserTerminal } from '../../out/browser/CoreBrowserTerminal';
|
|
|
|
perfContext('Terminal: ls -lR /usr/lib', () => {
|
|
let content = '';
|
|
let contentUtf8: Uint8Array;
|
|
|
|
before(async () => {
|
|
// grab output from "ls -lR /usr"
|
|
const p = spawn('ls', ['--color=auto', '-lR', '/usr/lib'], {
|
|
name: 'xterm-256color',
|
|
cols: 80,
|
|
rows: 25,
|
|
cwd: process.env.HOME,
|
|
env: process.env,
|
|
encoding: (null as unknown as string) // needs to be fixed in node-pty
|
|
});
|
|
const chunks: Buffer[] = [];
|
|
let length = 0;
|
|
p.onData(data => {
|
|
chunks.push(data as unknown as Buffer);
|
|
length += data.length;
|
|
});
|
|
await new Promise<void>(resolve => p.onExit(() => resolve()));
|
|
contentUtf8 = Buffer.concat(chunks, length);
|
|
// translate to content string
|
|
const buffer = new Uint32Array(contentUtf8.length);
|
|
const decoder = new Utf8ToUtf32();
|
|
const codepoints = decoder.decode(contentUtf8, buffer);
|
|
for (let i = 0; i < codepoints; ++i) {
|
|
content += stringFromCodePoint(buffer[i]);
|
|
// peek into content to force flat repr in v8
|
|
if (!(i % 10000000)) {
|
|
content[i];
|
|
}
|
|
}
|
|
});
|
|
|
|
perfContext('write/string', () => {
|
|
let terminal: CoreBrowserTerminal;
|
|
before(() => {
|
|
terminal = new CoreBrowserTerminal({ cols: 80, rows: 25, scrollback: 1000 });
|
|
});
|
|
new ThroughputRuntimeCase('', async () => {
|
|
await new Promise<void>(res => terminal.write(content, res));
|
|
return { payloadSize: contentUtf8.length };
|
|
}, { fork: false }).showAverageThroughput();
|
|
});
|
|
|
|
perfContext('write/utf8', () => {
|
|
let terminal: CoreBrowserTerminal;
|
|
before(() => {
|
|
terminal = new CoreBrowserTerminal({ cols: 80, rows: 25, scrollback: 1000 });
|
|
});
|
|
new ThroughputRuntimeCase('', async () => {
|
|
await new Promise<void>(res => terminal.write(contentUtf8, res));
|
|
return { payloadSize: contentUtf8.length };
|
|
}, { fork: false }).showAverageThroughput();
|
|
});
|
|
});
|