Conversation
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an idle-timeout feature to WebWorkerPool so that inactive web workers can be terminated after a configurable duration and recreated on-demand, with supporting scheduler updates and integration coverage in the test crate.
Changes:
- Add
idle_timeout_mstoWorkerPoolOptionsand an interval-based idle reaper that transitions workers to anEmptyslot state. - Refactor the pool from
Vec<WebWorker>to per-slotRefCell<WorkerSlot>and update scheduling to operate on per-slot load snapshots. - Add
WebWorker::last_active()tracking and an integration test validating idle termination and transparent recreation.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/pool/mod.rs |
Introduces idle-timeout configuration, WorkerSlot state machine, slot-based worker management, recreation logic, and active-worker metrics. |
src/pool/scheduler.rs |
Updates scheduler API to choose from Option<load> slots and return None when no active workers exist. |
src/webworker/worker.rs |
Adds last_active timestamp tracking updated on task completion for idle-timeout decisions. |
test/src/raw.rs |
Adds a JS sleep_ms helper and a new integration test for idle cleanup + recreation. |
test/src/lib.rs |
Wires the new idle-timeout test into the test runner. |
test/Cargo.toml |
Adds js-sys dependency and enables web-sys Window feature for timer usage. |
Cargo.lock |
Updates lockfile for the new js-sys dependency in the test crate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Workers with no pending tasks are automatically terminated after a configurable idle_timeout_ms duration and transparently recreated when new tasks arrive. Uses per-slot RefCell<WorkerSlot> instead of a single RefCell around the whole Vec, allowing independent borrowing so the idle checker and task execution never conflict.
b3c1adf to
84929d7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
idle_timeout_msoption toWorkerPoolOptions— workers with no pending tasks are terminated after the configured duration and transparently recreated on demandRefCell<WorkerSlot>so the idle checker and task execution can borrow independent slots without conflictlast_active()tracking toWebWorker,num_active_workers()toWebWorkerPool, and integration tests for idle cleanupTest plan
cargo +nightly fmt --all -- --checkpassescargo +nightly clippy --all-featurespasses (no warnings)cargo test --doc --all-featurespassescd test && npm ci && npm test(4/4 integration tests pass)