Skip to content

perf(sched): shorten the turns of a thread that spins while the threads it waits on run short turns - #100

Merged
Project516 merged 2 commits into
nextfrom
p516/vthread-speed
Nov 23, 2026
Merged

Project516 merged 2 commits into
nextfrom
p516/vthread-speed

Conversation

@Project516

Copy link
Copy Markdown
Owner

What this changes

The scheduler gives each thread turns of 20000 instructions. A thread that spins (for example on notify() in a loop) while the threads it waits on run short turns held the VM for most of the time: in CancelTimerWithContention the spinning main thread used 1849 of 1919 ms in one step.

  • A thread that stays runnable and runs turns longer than 50 µs, while other threads end short turns, gets its turn halved, down to 200 instructions.
  • It goes back to 20000 when it blocks, or when no other thread had a short turn.
  • Only a thread that stayed runnable after its turn reads the clock, so hand-offs between threads read no clock.
  • New test program test/java/SpinningNotifier.java: the main thread spins on notify() while 3000 virtual threads wait on the same locks.

Tests

  • pnpm test: 269 pass, 0 fail, 3 skipped. SpinningNotifier output matches HotSpot.
  • OpenJDK tests in passing.txt under java/lang/Thread, java/util/concurrent and java/lang/management: 76 pass, 3 time out (the JSR166TestCase entries, which also time out on next). ParkALot and GetStackTraceALotWhenBlocking pass.
  • CancelTimerWithContention step with 6400 threads: about 1 s on the branch, 10.5 to 11.4 s on next. CPU time for the 3200 and 6400 thread steps: 5.3 s against 17.8 s. The whole test now passes at a 600 s timeout (269 s and 443 s under load), so it stays out of passing.txt for now.
  • Four CPU-bound threads: 6.4 to 6.8 s on both. Park, wait and synchronized benchmarks match next within the spread over 5 alternating runs each.

Noticed, not fixed

  • Skynet100kWithMonitors still times out at 600 s on both: 10.4 to 13.6 s per round over 50 rounds. Its profile is flat (GC 8%, frame unpacking 4%, scheduler 8%), about 100 µs per virtual thread, so it needs faster Java execution in general rather than a scheduler change.
  • Running a spinning thread only once every 64 turns brought CancelTimerWithContention to 199 s, but made ParkALot and GetStackTraceALotWhenBlocking time out. A version that works needs a rule that never delays a thread another thread waits for.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c1cae894-8cff-4c65-9f11-f2dd8a87884a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PR reduces scheduler quantum for threads that spin while other threads run short turns. It adds per-thread quantum tracking and a global short-turn counter; when a thread stays runnable for over 50 µs while other threads have recently blocked, its turn is halved down to 200 instructions. A new test SpinningNotifier.java validates the fix.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

Comment thread src/jvm.ts Resolved
@Project516
Project516 merged commit 636a8e8 into next Nov 23, 2026
12 checks passed
@Project516
Project516 deleted the p516/vthread-speed branch November 23, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant