Repository navigation
fix(scheduler): keep source fairness runs across lifecycle turns - #2806
Merged
Merged
Conversation
lanyue-llk
commented
Nov 12, 2026
lanyue-llk
left a comment
Contributor
Author
There was a problem hiding this comment.
Independent review of 4d28ea4
No blocking findings
- Root cause: fixed.
record_selected_turn_classno longer resets the source run (page_turn_scheduler.rs:290-303), so the>= 8check at:327-331can now fire while lifecycle work is pending. This is the cause described in #2794, not a workaround for it. - The other direction: there is no new starvation. The change only touches
PageTaskArbitrationState. Class arbitration (consecutive_from_class,:256-271), the runnable-continuation priority (:229-235) andselect_lifecycle_turnwork exactly as before. A lifecycle turn still runs after at most 8 ordinary turns, so the load event is not delayed. A timer flood or a worker flood now gives another ready source (worker, network, timer) 1 turn in every 9 instead of none. That matches the existing behaviour when no lifecycle turn is pending. - Old test:
git log -S break_consecutive_runand-S lifecycle_turn_breaks_an_ordinary_sourceboth lead only to the squashed27b5135cb6 Public preview, so no rationale is recorded. The test asserted that the oldest source keeps winning after a lifecycle turn. HTML gives no ordering guarantee across task sources, and the module doc says fairness "is not an HTML cross-source ordering guarantee". The test therefore did not encode a real requirement, and replacing it is correct. The only other caller,document_write_resource_tests.rs:475, uses a fresh scheduler and is unaffected. - New test: on main the reset sets the counter to 0, so the 9th selection returns
DynamicImportOwnerActionand the newModulepreloadStartassertion fails. On the branch the counter is 8 and rotation selectsModulepreloadStart. So it fails on main and passes here, which I worked out from the code without running it. - Cost: the change removes one reset per lifecycle turn and adds no per-turn work. The body's numbers are plausible: the repro takes about 3.08 s wall time, mostly the 2.5 s async script.
- CI: Format, Node, Python and Windows pass. Nextest, Clippy, the release builds and CDP smoke were still pending when I reviewed.
- Picture: pending (the body has only the
<!-- picture -->placeholder).
ldm0
self-requested a review
November 12, 2026 09:35
Member
|
Awesome work! |
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.

Closes #2794. Replaces part of #1584.Problem. When a page has a pending lifecycle turn (for example an async script still loading) and a Worker floods the page with messages, a due timer can wait until the whole message backlog has drained. With the issue's page (
moli fetch URL --wait networkidle --dump html, a 250 mssetTimeoutstarted while 50,000 worker messages are queued and a 2.5 s async script is pending), Chromium reportsdata-worker-timer-delay="251". v1.1.23 reports ~2,600 ms, and a debug build of main reports 16-17 s.Change. In
runtime/page_turn_scheduler.rs,select_turn_classforces a document-lifecycle turn after 8 ordinary turns.record_selected_turn_classthen calledPageTaskArbitrationState::break_consecutive_run(), which reset the per-source run counter.select_ready_descriptorrotates to another source only after a source has run 8 times in a row, so the counter was always reset first and rotation never happened while lifecycle work was pending. The reset and the helper are removed. A lifecycle turn is not an ordinary-source selection, so it neither extends nor ends the current source's run. The existing testlifecycle_turn_breaks_an_ordinary_source_consecutive_runencoded the old behaviour. It becomeslifecycle_turn_keeps_an_ordinary_source_consecutive_run, which asserts that the 9th selection from the dominant source rotates to the other ready source even with a lifecycle turn in between.Verification.
--wait networkidle --dump html:2619,2677,2617;17239,16444,16490;251,251,250,251,251(Chromium 251).cargo nextest run -p moli-renderer-v8 -E 'test(page_turn_scheduler)': 23 passed.cargo nextest run -p moli -p moli-core -E 'test(networkidle) | test(worker) | test(timer)': 515 of 516 passed. The failure wascli_quiet_page_networkidle_uses_remaining_best_effort_budget, a test that leaves 250 ms of budget. On re-runs the pair ofcli_quiet_page_*tests passed in 8 of 10 runs while the host load average was ~8-10, and in 6 of 6 runs once load dropped. The same scenario run directly (500 ms page,--timeout 750, 15 interleaved runs each) passed 15/15 on both main and this branch for networkidle and domstable. The quiet page has no lifecycle-plus-flood contention, so the scheduler change does not affect it. CI is the authority.cargo fmt --allclean;cargo clippy -p moli-renderer-v8 --all-targets --all-features -- -D warningsclean (workspace clippy not run locally).Cost. The change removes work: one counter reset per lifecycle turn. The fairness override still applies only after 8 consecutive tasks from one source while another source is ready, so ordinary pages schedule as before. The debug builds compared are main cbf4d01 and this branch (main 6786667 + this change), with the same profile,
/usr/bin/time -l, alternating runs, median of 7:--wait networkidle--wait networkidle