Skip to content

perf: warm CDP WebSocket browser pipeline for ResidentServer screenshots - #292

Open
IoannisMaras wants to merge 1 commit into
iOfficeAI:mainfrom
IoannisMaras:perf/resident-cdp-screenshot
Open

perf: warm CDP WebSocket browser pipeline for ResidentServer screenshots#292
IoannisMaras wants to merge 1 commit into
iOfficeAI:mainfrom
IoannisMaras:perf/resident-cdp-screenshot

Conversation

@IoannisMaras

Copy link
Copy Markdown

Speed up screenshots using warm CDP WebSocket connection in ResidentServer

What this PR does

Spawning a fresh chrome.exe process for every screenshot command was taking ~2.5 seconds per capture due to process creation, V8 startup, and disk file I/O.

This PR connects Chrome to ResidentServer using Chrome DevTools Protocol (CDP) over a WebSocket connection:

  1. Reuses Chrome in background: When ResidentServer starts, it opens a single background Chrome process (chrome-headless-shell, chrome, or edge) and keeps a WebSocket open to it.
  2. In-memory HTML injection: Passes HTML directly over the WebSocket as data:text/html;base64 instead of writing temporary .html files to disk first.
  3. Clean teardown: When the 120-second idle watchdog timer shuts down ResidentServer (or when running officecli close), it closes the WebSocket and kills the Chrome process cleanly so zero memory or CPU is leaked.
  4. Output identity: Renders 100% byte-identical PNG images compared to cold single-shot Chrome captures.

Performance Results

When paired with PR #1 (PR #289), end-to-end screenshot execution time drops from ~2.4 seconds down to ~148 ms:

1. Cold Startup Phase (First time launching background server & browser)

  • Original main Cold Run: ~2,450 ms
  • New CDP Cold Setup (Run 1–2): ~1,478 ms – 1,712 ms (~800 ms faster due to chrome-headless-shell & zero-disk HTML injection)

2. Warm Resident Execution Phase (Subsequent commands while active)

  • Original main: ~2,450 ms (spawns new Chrome process every single time)
  • Warm CDP Resident Mode (Runs 3–5): ~148 ms – 165 ms (~16x faster!)

Execution Breakdown (~148 ms total)

  • officecli.exe process launch: ~105 ms
  • Named Pipe IPC to ResidentServer: ~8 ms
  • OpenXML to HTML conversion: ~5 ms
  • Chromium WebSocket render & PNG capture: ~30 ms

How it was tested

  • Verified 5/5 runs 100% PNG output byte match on .docx, .xlsx, and .pptx.
  • Tested clean process shutdown after 120s idle timeout and officecli close.
  • Tested fallback path when Chrome/Edge is not installed or when running non-resident commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant