Skip to content

Commit e4723c0

Browse files
authored
perf(cf): reduce checkbox poll interval from 200ms to 50ms (#130)
DOM.getDocument is ~2-6ms, so 50ms polling is well within margin. Saves ~75ms avg per scrape on checkbox cold start detection. At millions of scrapes this adds up to real hours saved. MAX_CHECKBOX_POLLS increased from 16 to 64 to maintain the same 3.2s total wait window.
1 parent c112483 commit e4723c0

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/session/cf/cf-schedules.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ export const OOPIF_POLL_DELAY = '200 millis' as const;
7979
* preventing stale/closing OOPIFs from blocking for the 30s CDP default. */
8080
export const OOPIF_PROBE_TIMEOUT = '3 seconds' as const;
8181

82-
/** Phase 3 checkbox polling: max attempts. */
83-
export const MAX_CHECKBOX_POLLS = 16;
82+
/** Phase 3 checkbox polling: max attempts.
83+
* 64 × 50ms = 3.2s total window (same as previous 16 × 200ms). */
84+
export const MAX_CHECKBOX_POLLS = 64;
8485

8586
/** Phase 3 checkbox polling: interval between attempts (ms).
86-
* Reduced from 500 to 200 — DOM.getDocument is ~2-6ms, so 200ms gives
87-
* plenty of margin while detecting the checkbox 2.5x faster. */
88-
export const CHECKBOX_POLL_INTERVAL_MS = 200;
87+
* Reduced from 200 to 50 — DOM.getDocument is ~2-6ms, so 50ms gives
88+
* plenty of margin. Saves ~75ms avg per scrape (1.6-4.8s CF WASM init). */
89+
export const CHECKBOX_POLL_INTERVAL_MS = 50;
8990

9091
/** Clean WS open timeout (ms). */
9192
export const CLEAN_WS_OPEN_TIMEOUT_MS = 2_000;

src/session/cf/cloudflare-solver.integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ describe('CF Solver Integration (real nopecha.com)', () => {
404404
const polls = Number(checkboxFound!.payload.polls ?? 0);
405405
console.log(` checkbox: found_at=${findMs}ms polls=${polls} method=${checkboxFound!.payload.method}`);
406406

407-
// MAX_CHECKBOX_POLLS = 16 in cf-schedules.ts — solver's actual polling budget.
407+
// MAX_CHECKBOX_POLLS = 64 in cf-schedules.ts — solver's actual polling budget.
408408
// nopecha.com's Turnstile widget render time varies by CF's server-side timing.
409-
expect(polls).toBeLessThanOrEqual(16);
409+
expect(polls).toBeLessThanOrEqual(64);
410410
expect(findMs).toBeLessThan(10_000);
411411

412412
// Verify poll interval via phase3_strategy markers
@@ -420,7 +420,7 @@ describe('CF Solver Integration (real nopecha.com)', () => {
420420
const sleepGap = gap - cdpMs;
421421
console.log(` poll_gap: ${gap}ms (cdp=${cdpMs}ms, sleep≈${sleepGap}ms)`);
422422
// Isolate sleep interval from CDP call time.
423-
// CHECKBOX_POLL_INTERVAL_MS = 200 + scheduling overhead ≈ < 500ms.
423+
// CHECKBOX_POLL_INTERVAL_MS = 50 + scheduling overhead ≈ < 500ms.
424424
expect(sleepGap).toBeLessThan(500);
425425
// Full gap sanity: even with slow CDP under concurrent load, < 3s
426426
expect(gap).toBeLessThan(3000);

0 commit comments

Comments
 (0)