From 8c1946e2da633fe58c05ad7c24f8a46631298fdd Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Thu, 30 Jul 2026 21:40:53 -0700 Subject: [PATCH] perf(terminal): keep uncontended paste delivery synchronous --- .../terminal-paste-operation-order.test.ts | 10 ++++++++++ .../terminal-pane/terminal-pty-input-transaction.ts | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/components/terminal-pane/terminal-paste-operation-order.test.ts b/src/renderer/src/components/terminal-pane/terminal-paste-operation-order.test.ts index b0f874d50f8..b36f0d06f65 100644 --- a/src/renderer/src/components/terminal-pane/terminal-paste-operation-order.test.ts +++ b/src/renderer/src/components/terminal-pane/terminal-paste-operation-order.test.ts @@ -32,6 +32,16 @@ function chunkedWindowsPaste() { } describe('terminal paste operation ordering', () => { + it('starts an uncontended paste operation synchronously', async () => { + let started = false + const operation = runTerminalPtyInputTransaction('pty-1', async () => { + started = true + }) + + expect(started).toBe(true) + await operation + }) + it('keeps startup context outside an active chunked user paste frame', async () => { const writes: string[] = [] let startupDraft: Promise | null = null diff --git a/src/renderer/src/components/terminal-pane/terminal-pty-input-transaction.ts b/src/renderer/src/components/terminal-pane/terminal-pty-input-transaction.ts index 8a4303bcc5f..e6c0239751b 100644 --- a/src/renderer/src/components/terminal-pane/terminal-pty-input-transaction.ts +++ b/src/renderer/src/components/terminal-pane/terminal-pty-input-transaction.ts @@ -8,14 +8,16 @@ export async function runTerminalPtyInputTransaction( return await operation() } - const previous = transactionTails.get(ptyId) ?? Promise.resolve() + const previous = transactionTails.get(ptyId) let release!: () => void const current = new Promise((resolve) => { release = resolve }) transactionTails.set(ptyId, current) - await previous + if (previous) { + await previous + } try { return await operation() } finally {