Skip to content

test: make the unit suite ~2x faster - #3858

Merged
karlseguin merged 5 commits into
mainfrom
test-speedup
Oct 8, 2026
Merged

karlseguin merged 5 commits into
mainfrom
test-speedup

Conversation

@arrufat

@arrufat arrufat commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Half of the `make test` wall time was idle: a cached run took 23.7s wall but only ~12s CPU. This removes most of the idle time plus a few oversized CPU loops. It brings a cached `make test` to ~11.8s. Coverage is unchanged.

Harness idle (the bulk of it)

  • The CDP and BiDi test harnesses set a 5ms `SO_RCVTIMEO` on the test side of the socketpair, so every `read()` blocked 5ms before returning `WouldBlock`. CDP's `expectSent` also slept 5ms per retry.
  • Replies are written synchronously, so the test socket is now non-blocking. On a miss, `expectSent` ticks the page (20ms max per tick) until a 2s deadline.
  • Results: cdp group 9.2s → 1.8s, bidi 1.7s → 0.4s.

Waited-out timeouts and fixture delays

  • Timeout-path tests wait out their full timeout, so those timeouts are now small:
    • goto 300 → 50ms
    • MCP/LP `waitForSelector` 100 → 20ms
    • WebDriver script timeout 50 → 20ms
  • Smaller sleeps in `createHTTPSession` and the sqlite pool test.
  • `fetch.html` and `performance.html` no longer wait 100ms before posting to a worker. Messages posted before the worker script runs are already queued (`drainPendingMessages`).
  • Shorter waits in `image_fetch.html` (it now awaits `load`), `xhr.html` and `isolated_world_redirect.html`.

CPU-heavy tests

  • IntersectionObserver chain: sentinels are now inserted first. Appending them made each `getBoundingClientRect` walk every earlier sibling, so the 1024-long chain was quadratic. Saves ~0.6s.
  • XPath deep nesting: depth 100k → 50k. I measured this by reverting 2994295 on HEAD: the recursive evaluator overflows an 8MB stack at depth ~35k in debug builds, so 50k still catches a regression.
  • header_parser: still every byte at every position, but only for the lengths at the 16/32-byte vector, 8-byte SWAR and scalar path boundaries.
  • Dropped the second run of `cdata/comment.html`, which the `cdata` directory run already covers.

Not in this PR

  • Parallel (sharded) test runs will stack on top of this PR. They need the fixed 9582–9584 ports and the shared `/tmp` files parameterized first.
  • The 500ms network-idle hold, which one Runner test waits out (~0.7s). Fixing it would mean a test-only override of a production constant.

Every read on the test socket waited out a 5ms SO_RCVTIMEO before
returning, and a CDP expectSent miss slept another 5ms on top. Replies
are written synchronously, so the test side of the socketpair is now
non-blocking and expectSent ticks the page until a 2s deadline instead
of sleeping.
Timeout-path tests wait out their whole timeout, so keep those small.
Workers queue messages posted before their script runs, so the 100ms
delays before postMessage were never needed.
- IntersectionObserver chain: insert sentinels first; appending made
  every check walk all earlier siblings, so the chain was quadratic.
- XPath deep nesting: the recursive evaluator overflowed an 8MB stack
  at a depth of about 35000 in debug builds, so 50000 still catches a
  regression at half the cost of 100000.
- header_parser: keep every byte at every position, but only for the
  lengths straddling the vector, SWAR and scalar path boundaries.
- Drop the second run of cdata/comment.html, already covered by the
  cdata directory run.
The goto test reused its 50ms stuck-navigation timeout for the load that
must succeed, which a tsan debug build can't finish in time. The script
timeout also stays in force for later executeSync calls, so it goes back
to 50ms.
Comment thread src/server/Server.zig Outdated
The sleep between headers and body made every session test pay for a
case it might not even trigger; that case gets its own test.
@arrufat arrufat changed the title test: speed up make test (23.7s → 11.8s) test: make the unit suite ~2x faster Oct 8, 2026
@karlseguin

Copy link
Copy Markdown
Collaborator

Can you re-run the zig-test job a few times to make sure it passes reliably?

@arrufat

arrufat commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Can you re-run the zig-test job a few times to make sure it passes reliably?

I ran them 4 extra times successfully, both this PR and #3860

@karlseguin
karlseguin merged commit f4ffd65 into main Oct 8, 2026
38 checks passed
@karlseguin
karlseguin deleted the test-speedup branch October 8, 2026 15:06
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants