Repository navigation
test(bun:jsc): bound profile() workload by wall-clock so the sampler always fires - #33998
Conversation
…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.
WalkthroughChangesProfiling test update
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
|
Updated 11:30 PM PT - Jul 11th, 2026
❌ @robobun, your commit 00f0e94 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 33998That installs a local version of the PR into your bun-33998 --bun |
There was a problem hiding this comment.
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...whileguarantees at least onefib(18)call, andaccis 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
accaccumulator is returned fromwork(), preventing the JIT from eliminating thefib(18)calls as dead code. - The
do...whilestructure guarantees at least one iteration even ifperformance.now()resolution were coarse. - The test's original purpose — verifying the profiler can be reused after
pause()(vs the buggyshutdown()) — 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.
There was a problem hiding this comment.
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+ returnedacckeeps 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 onefib(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
accreturn 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 thanshutdown()) is preserved: a shut-down sampler produces zero traces no matter how long the workload runs, so thetoBeGreaterThan(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.
|
CI status: Remaining red is unrelated to this diff:
This is a test-only change to one assertion's workload; ready for maintainer merge. |
Fixes
test/js/bun/jsc/bun-jsc.test.tsgoing red on the debian 13 x64 lane in build 72010: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 fromfib(30)tofib(26)so three runs fit inside the per-test timeout on slow debug builds. On fast release hardware a JIT-compiledfib(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 perprofile()call instead of relying on a singlefib(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 afterpause()/start(). On debug builds the loop still exits after ~12ms of JS work (onefib(18)of overshoot), so the test is no slower there than before.The test still catches the original regression from #25939 (using
shutdown()instead ofpause()): 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 callbun 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.