perf(cookies): parallelize browser strategy queries#491
Conversation
Replace sequential for-of loop with Promise.allSettled so Chrome, Firefox, and Safari are queried in parallel. Each strategy targets independent databases with zero data dependency. Fixes #485
There was a problem hiding this comment.
The parallelization change is correct and well-structured.
What the PR does well:
👍 Promise.allSettled is the right primitive — it guarantees all three browser strategies are always attempted, even if one fails early. Using Promise.all here would have short-circuited on the first failure when continueOnError = false.
👍 Error handling semantics are preserved — the continueOnError flag is threaded through both the inner queryStrategy calls and the new outer settlement loop.
👍 Independent I/O is the correct justification — Chrome, Firefox, and Safari each read from completely separate database files, so parallel access is safe and there are no shared resources or ordering constraints to worry about.
One minor observation worth noting (non-blocking):
🔵 "rejected" branch in the outer loop is a narrow path when continueOnError = false — queryStrategy already catches internally and re-throws when continueOnError = false, so Promise.allSettled captures that throw as a rejected result. The outer else { throw result.reason } then re-throws it. This is functionally correct, but it means an uncaught exception in queryStrategy (e.g., from something outside the try/catch block like the strategy constructor throwing) would also land here. The current code handles that correctly, so this is purely an observation rather than a bug.
🔵 No direct unit tests for the parallel behavior in batchQueryCookies itself — existing tests mock out batchQueryCookies entirely. A test verifying that all three strategies are invoked concurrently (e.g., using spies to detect overlapping execution) would add confidence, but the existing integration path through batchGetCookies covers the happy path.
Overall the change is minimal, well-reasoned, and the test plan confirms all 588 tests pass. Ready to merge.
Summary
for...of awaitloop withPromise.allSettledinbatchQueryCookiesso Chrome, Firefox, and Safari are queried in parallelcontinueOnErrorflag respected)Closes #485
Test plan