Skip to content

Run Rayon jobs through its single-threaded fallback wake hook - #3

Open
guybedford wants to merge 2 commits into
danlapid:mainfrom
guybedford:rayon-fallback-hook
Open

guybedford wants to merge 2 commits into
danlapid:mainfrom
guybedford:rayon-fallback-hook

Conversation

@guybedford

@guybedford guybedford commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Integrates the latest Rayon PR feedback on rayon-rs/rayon#1323 implementing a new set_fallback_wake_hook so Pumpkin's stock rayon::spawn works on the single-threaded target.

Without threads Rayon's global pool is the current-thread fallback, and a spawned job only runs when the thread next yields to Rayon; the Pumpkin patch worked around that by rewriting nine rayon::spawn call sites to a pumpkin_util::rayon_spawn shim. With the hook the object drives the queue from the event loop, so each job takes a turn of its own, and those rewrites and the shim go away (patch -114 lines).

  • rayon/rayon-core pinned to guybedford/rayon fallback-spawn in [patch.crates-io] until #1323 releases
  • MinecraftWorld::new installs the hook with a driver: one rayon::yield_now() per spawn_local turn, rescheduling itself while a job ran. A wake fires once per idle-to-pending transition, so a single yield per wake leaves jobs queued behind it stranded until the next transition (chunk encoding stalled that way); the driver runs until Idle
  • pumpkin-emscripten.patch: rayon_spawn removed, call sites back to rayon::spawn; chunk generation keeps its Tokio task on single-threaded builds since upstream runs it on a private ThreadPoolBuilder pool the fallback does not cover

npm test passes (PUMPKIN-DO-SQLITE-RESTART-OK); native scheduler and chunk-queue tests pass.

The tag moved to 7227f2d7: hosted event loops are driven as a microtask from
host callbacks, wakes are coalesced only within a drive, and
emscripten_epoll_remove_listener receives its userdata.
rayon-rs/rayon#1323 lets a host without threads learn when a job has been
queued on the global fallback pool. The object installs the hook with a
driver that runs one `rayon::yield_now()` per turn of the event loop until
the queue is idle (a wake fires once per idle-to-pending transition, so one
yield per wake would leave jobs queued behind it), so every `rayon::spawn`
in Pumpkin runs as its own turn, and the Pumpkin patch drops the
`rayon_spawn` shim and its call-site rewrites. Chunk generation keeps its
Tokio task on single-threaded builds, as upstream runs it on a private pool.
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