Skip to content

test(bun:jsc): bound profile() workload by wall-clock so the sampler always fires - #33998

Merged
dylan-conway merged 2 commits into
mainfrom
farm/4daf758a/deflake-jsc-profile-multiple
Jul 20, 2026
Merged

dylan-conway merged 2 commits into
mainfrom
farm/4daf758a/deflake-jsc-profile-multiple

Conversation

@robobun

@robobun robobun commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes test/js/bun/jsc/bun-jsc.test.ts going red on the debian 13 x64 lane in build 72010:

215 |     expect(result2.stackTraces.traces.length).toBeGreaterThan(0);
error: expect(received).toBeGreaterThan(expected)
Expected: > 0
Received: 0
✗ bun:jsc > profile can be called multiple times [4.71ms]

Cause

The test profiles fib(26) three times at a 50µs sample interval and asserts each run collected at least one trace. #33072 shrank the workload from fib(30) to fib(26) so three runs fit inside the per-test timeout on slow debug builds. On fast release hardware a JIT-compiled fib(26) can finish inside one 50µs interval (the whole 3-call test completed in 4.71ms there), so the sampler thread simply never fires during the second call.

This is the same race #28873 addressed by lowering the sample interval; lowering the instruction count in #33072 reopened it.

Fix

Loop fib(18) for a fixed 10ms of wall-clock per profile() call instead of relying on a single fib(n) being slow enough. 10ms is ~200 sample intervals, so the sampler thread is guaranteed time to fire regardless of JIT tier or how slowly it wakes after pause()/start(). On debug builds the loop still exits after ~12ms of JS work (one fib(18) of overshoot), so the test is no slower there than before.

The test still catches the original regression from #25939 (using shutdown() instead of pause()): a shut-down sampler returns zero traces no matter how long the workload runs.

Verification

  • USE_SYSTEM_BUN=1 bun test test/js/bun/jsc/bun-jsc.test.ts -t 'profile can be called multiple times': 30/30 pass, ~80 traces per call
  • bun bd test test/js/bun/jsc/bun-jsc.test.ts: 36 pass / 0 fail, profile test ~1.6s (dominated by the profiler's JSON reporting, same as before)

This is a timing flake that does not reproduce on the dev container (fib(26) takes ~800µs there after JIT warmup, well above 50µs), so there is no deterministic fail-before to show; the CI failure above is the reproduction.


no test proof · iteration 2 · Platform-specific test-only change; deferring to CI.

…always fires

The 'profile can be called multiple times' test profiles fib(26) three times
and asserts each run collected at least one stack trace. #33072 shrank the
workload from fib(30) to fib(26) so three runs fit inside the per-test
timeout on slow debug builds, but on fast release hardware a JIT-compiled
fib(26) can finish inside one 50us sample interval, so the second profile()
call observes zero traces and the test fails (seen on debian 13 x64 in
build 72010).

Loop fib(18) for a fixed 10ms of wall-clock instead. That gives the sampler
thread at least 200 intervals regardless of JIT tier or sampler-thread
wakeup latency after pause()/start(), and keeps each profile() call under
15ms of JS work on both release and debug. The test still catches the
original regression from #25939 (shutdown() vs pause()): a shut-down
sampler returns zero traces no matter how long the workload runs.
@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Profiling test update

Layer / File(s) Summary
Time-bounded workload and repeated profiling
test/js/bun/jsc/bun-jsc.test.ts
The test introduces a reusable work callback that repeatedly computes fib(18) for approximately 10ms, then profiles it across three sequential invocations while retaining existing result and stack-trace assertions.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: time-bounding the profile workload to keep the sampler firing.
Description check ✅ Passed It includes the change, cause, fix, and verification, covering the template's required intent even though the exact headings differ.

Comment @coderabbitai help to get the list of available commands.

@robobun

robobun commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 11:30 PM PT - Jul 11th, 2026

❌ @robobun, your commit 00f0e94 has 1 failures in Build #72060 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 33998

That installs a local version of the PR into your bun-33998 executable, so you can run:

bun-33998 --bun

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — straightforward test de-flake that bounds the profiled workload by wall-clock instead of instruction count.

What was reviewed:

  • Confirmed performance.now() is in ms, so the 10ms window covers ~200 sample intervals at 50µs — sampler is guaranteed to fire.
  • do...while guarantees at least one fib(18) call, and acc is returned so the JIT can't DCE the loop body.
  • Test still catches the original #25939 regression: a shut-down sampler returns zero traces regardless of how long work() runs.
  • 3×10ms is well under the per-test timeout on both debug and release; no new flakiness introduced.
Extended reasoning...

Overview

This PR modifies a single test case in test/js/bun/jsc/bun-jsc.test.ts — the "profile can be called multiple times" test. It replaces three profile(() => fib(26), 50) calls with profile(work, 50), where work() busy-loops fib(18) until 10ms of wall-clock time has elapsed. The change is test-only; no runtime code is touched.

Security risks

None. This is a test-file-only change with no impact on shipped code, no external inputs, and no security-sensitive surface.

Level of scrutiny

Low. The change is a targeted de-flake of a known-flaky test (CI failure linked in the PR description), touches ~15 lines in one test file, and follows the repo's own guidance about awaiting conditions rather than relying on fixed instruction counts. The root cause analysis is sound: #33072 shrank fib(30)→fib(26) to fit debug-build timeouts, which reopened the race #28873 had closed by lowering the sample interval — on fast release hardware, JIT-compiled fib(26) completes inside one 50µs interval. Bounding by wall-clock decouples the workload from JIT tier entirely.

Other factors

  • The acc accumulator is returned from work(), preventing the JIT from eliminating the fib(18) calls as dead code.
  • The do...while structure guarantees at least one iteration even if performance.now() resolution were coarse.
  • The test's original purpose — verifying the profiler can be reused after pause() (vs the buggy shutdown()) — is preserved: a shut-down sampler yields zero traces no matter how long the workload runs, so the .toBeGreaterThan(0) assertions still fail on that regression.
  • 30ms total workload (3×10ms) is comfortably under any test timeout on both debug and release builds, and is wall-clock-bounded so it won't balloon on slow debug+ASAN runs the way a fixed fib(n) would.
  • No prior human or bot reviews on this PR to consider.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only de-flake that bounds the profiled workload by wall-clock instead of a fixed fib(n) instruction count.

What was reviewed:

  • Confirmed the do...while + returned acc keeps the JIT from eliding the work, and 10ms ≫ the 50µs sample interval so the sampler must fire.
  • Verified the test still catches the original #25939 regression: a shut-down sampler yields zero traces regardless of workload duration, so toBeGreaterThan(0) still fails in that case.
  • Checked that performance.now() is monotonic (won't loop forever on clock adjustment) and that debug-build overshoot is bounded to one fib(18).
Extended reasoning...

Overview

Single-file test change to test/js/bun/jsc/bun-jsc.test.ts, in the "profile can be called multiple times" test. Replaces three profile(() => fib(26), 50) calls with profile(work, 50) where work busy-loops fib(18) for ≥10ms wall-clock. No runtime code is touched.

Security risks

None. Test-only; no user-facing surface, no untrusted input, no auth/crypto/permissions.

Level of scrutiny

Low. This is a targeted de-flake of a known-flaky assertion with a well-documented history (#28873 lowered the sample interval, #33072 shrank the workload and reopened the race, this PR bounds by wall-clock so neither JIT tier nor hardware speed can drop the workload below one sample interval). The mechanism is sound: 10ms at a 50µs interval gives ~200 sampling opportunities, and do...while guarantees at least one fib(18) even if performance.now() returned instantly.

Other factors

  • The acc return value prevents the JIT from dead-code-eliminating the loop body.
  • performance.now() is monotonic, so the loop cannot spin indefinitely on wall-clock adjustments.
  • The test's original purpose (verifying the profiler can be reused after pause() rather than shutdown()) is preserved: a shut-down sampler produces zero traces no matter how long the workload runs, so the toBeGreaterThan(0) assertion still fails on regression.
  • The new comment block is 5 lines vs. the CLAUDE.md 3-line guideline; this was raised and ruled out as a nit — the surrounding file already has multi-line explanatory comments and the context (why a fixed fib(n) is insufficient) is worth keeping.
  • No CODEOWNERS entry covers this path. No prior human review comments to address.

@robobun

robobun commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

CI status: bun-jsc.test.ts passed clean on every lane across both build 72030 and build 72060 (not in any error or flaky annotation).

Remaining red is unrelated to this diff:

  • build 72060: darwin-14-aarch64-test-bun expired waiting for an agent (never ran); 283 jobs passed, 0 failed
  • build 72030: git clone vendor 'elysia': timeout on darwin-x64, rustup toolchain misconfig on darwin-aarch64, plus pre-existing test-worker-message-port-transfer-terminate.js / proxy-stress-matrix.test.ts / wpt-h2/run.test.ts failures

This is a test-only change to one assertion's workload; ready for maintainer merge.

@dylan-conway
dylan-conway merged commit 0a17ce6 into main Jul 20, 2026
76 of 77 checks passed
@dylan-conway
dylan-conway deleted the farm/4daf758a/deflake-jsc-profile-multiple branch July 20, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants