perf: event-driven CDP readiness detection (−55s startup)#1452
Open
lennney wants to merge 1 commit into
Open
Conversation
Owner
|
当前 PR 的 Windows artifacts 检查仍然失败,暂时不能合并。最新 |
Replaces the 120×1s polling loop with three-phase progressive detection, cutting typical startup from ~55s to 0-2s. Phase 1: Monitor stderr for Chrome/Electron's 'DevTools listening on ws://' signal (Playwright pattern). Magic line found → immediate injection attempt via oneshot. Phase 2: Exponential backoff TCP probing (100ms→10s) for packaged apps where stderr is unavailable. Phase 3: 1s-interval polling (30 attempts) as safety net — matches original behaviour. Also eliminates nested retry: self.inject() called retry_injection (20×500ms loop), creating a hidden 10s barrier. Phases 2 & 3 now use try_inject() for a single TCP probe per attempt. Key design: wait_for_cdp_ready returns Ok(()) ONLY on magic line, Err on EOF. The spawn calls tx.send(()) only on success, ensuring Phase 1 fast path is genuinely reachable (distinct from EOF). 4 mock tests cover detection, noise tolerance, EOF, and empty input.
68cf7b7 to
63e337d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the 120×1s polling loop in ensure_injection with three-phase progressive CDP readiness detection. Typical startup drops from ~55s to 0-2s.
Design
DevTools listening on ws://→ immediate injectionPhase 1 follows Playwright's Electron launcher pattern (92k★): pipe child stderr, match DevTools signal line. All Chromium-based apps print this when launched with
--remote-debugging-port.Key correctness detail
wait_for_cdp_readyreturnsOk(())only when the magic line is found; EOF returnsErr. The spawn callstx.send(())only on success. This ensures Phase 1's fast path is genuinely reachable — distinct from EOF / I/O errors.Also eliminates nested retry:
self.inject()internally calledretry_injection()(20×500ms), creating a hidden 10s delay. Phases 2 & 3 usetry_inject()for a single TCP probe per attempt.Performance
Test Coverage
4 mock tests for
wait_for_cdp_ready:All 64 launcher tests pass.