Repository navigation
fix(wait): keep domstable open for async scripts, starting iframes and workers - #2776
lanyue-llk wants to merge 3 commits into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 37bd3a6
Changes needed (1)
- Brief loads now switch domstable to the longer 1200 ms quiet window, adding about 850 ms on ordinary pages.
moli-renderer-v8/src/runtime/page_dom.rs:1492-1500. The three new signals are ORed intopending_runtime_work, and line 1497 latches that value intostate.saw_post_domcontentloaded_runtime_work. Once the latch is set,dom_stable_window_for_snapshot(page_dom.rs:132-137) usesDOM_STABLE_COMPLETE_RUNTIME_WINDOW(1200 ms) instead of the 350 ms base window for the rest of the wait. So a page with an analyticsasyncscript or an ad/embed iframe that is pending for even one 120 ms poll now pays the long window, even though nothing is left running.- Measured on v1.1.23 (local server, 200 ms delay,
--wait domstable):async.htmlreturns in 0.60 s,frame.htmlin 0.61 s, plain page in 0.40 s. Under this change both will take about 1.45 s. Your own table shows the extra window: classic async with a 3 s delay takes 4.29 s, buttype=modulewith the same 3 s delay takes 3.45 s. - Smallest fix: keep the three load signals in the "do not start the timer" gate and in the snapshot's
pending:field, but leave them out of thesaw_post_domcontentloaded_runtime_worklatch. For example, computepending_loadsseparately and usepending_subresource_requests == 0 && !pending_runtime_work && !pending_loads. The base window is still safe here: when the loaded script starts afetch()it counts as a subresource, and a timer longer than 350 ms is already caught byhas_long_pending_timeout. The worker case should still pass, because the worker'spostMessagereaches the page as a DOM change after the load finishes.
- Measured on v1.1.23 (local server, 200 ms delay,
Checked, not blocking:
- Unbounded pending state. A 404 or failed worker script calls
forget_worker(script_vm/dedicated_worker_client_event_body.rs:~170), andterminate()forgets the worker too, so neither staysLoading. Long-lived running workers are not counted, becausehas_loading_dedicated_workerscounts onlyLoading. For a never-loading iframe or a hanging async script, networkidle already waits the same way:has_pending_child_document_lifecycleis the same signal inpage_network.rs:36, and on v1.1.23 a 60 s async script makes networkidle use the whole 4 s--timeout. In every case the shared deadline returns the best-effort page (moli-core/src/runtime/mod.rs:851-869). One difference: networkidle ignores worker script loads. On v1.1.23 a 60 s worker script gives networkidle 0.56 s, but with this change domstable will wait the whole--timeout(25 s by default). This matches how domstable already treats a hangingfetch(), and the fixed deadline still bounds it, so I am not counting it as a finding. - Navigation. Workers are cleared with their realm (
retire_window_realm_resources, the same path as WebCrypto and OPFS). The async-delay check is scoped to the current main-document owner, and the child lifecycle is scoped to current owners.TriggeredNavigationis checked before the signals. - Default path.
--wait done, the CLI default, does not use the domstable wait (moli/src/app/readiness.rs:59-71), so it is unaffected. - Test. The new fixture runs each kind with a 1.8 s delay. Without the fix, every kind would return at the 1.2 s interactive window, so the test fails. It does not lock in any behavior that differs from Chromium.
- CI. Nextest, Clippy, Format and CDP smoke pass. The release builds are still pending.
- Body. The Cost section and the picture are pending.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 34cb4f2
No blocking findings
Checked:
- Round 1 fix.
moli-renderer-v8/src/runtime/page_dom.rs:1497-1504:pending_loadsis computed after thesaw_post_domcontentloaded_runtime_worklatch and never feeds it. It only gates the stability timer (line 1518) and the snapshot'sruntime:field (line 1513). So once a load ends, the snapshot changes, the timer restarts, anddom_stable_window_for_snapshot(page_dom.rs:126-141) picks the 350 ms base window for acompletedocument. While an async script or iframe is still pending, the document isinteractive, so the stability window is 1200 ms either way. This also explains why the earlier 4.29 s async result is now ~3.5 s. - Whole diff. Making
has_post_domcontentloaded_load_delaying_runtime_workpub(crate)changes only its visibility. It still returns false before DOMContentLoaded and is scoped to the current main-document owner.has_loading_dedicated_workerscounts onlyLoadingworkers (context_host/activity.rs:301), so running workers do not hold the wait.has_pending_child_document_lifecycleis the signal networkidle already uses. Every wait stays bounded by the shared deadline. - Cost. The numbers are plausible. Ordinary page 0.42 vs 0.43 s. 200 ms async/iframe match v1.1.23 (0.60/0.61 s in round 1), which confirms no long window. Long delays are about load + 350 ms + overhead (3.48, 2.26, 2.24 s). RSS changes are noise.
- Test. Each of the three kinds uses a 1.8 s delay, longer than the 1.2 s interactive window, so the test fails without the fix. It does not lock in any behavior that differs from Chromium.
- Body/picture. The picture matches the current body: the
pending_loadsdiagram with the "not latched, 350 ms" note, the before/after table and the first three Cost rows.Closes #2770, the title format and the not-run statements are accurate. - CI. Format, Windows storage, Node and Python harness pass. Nextest, Clippy, CDP smoke and the release builds are still pending, so their results are not judged here.
|
Hmmm, this change would make time-to-domstable on some pages dramatically larger. |
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary 0.00%Package and image size
Startup latency and PSS
Concurrency matrix
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
CDP smoke — ✅ 118/118 groups passed; 1,784 scenariosWorkers: 4 · cumulative group time: 399.96 s · failed groups: 0
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Frozen HTML · Linux · Diagnostics: All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable. |
Spider Bench A/B✅ All benchmark browser service runs completed; results are informational. Public HEAD: 184 / 240 rows; 38 / 48 sites produced rows; 10 unexpected empty sites. ✅ Deterministic fixture contract is clean. Common ancestor Public 48-site run · informational
Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression. CPU and memory timelinesThese are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available. Basexychart-beta
title "Base CPU"
x-axis "Elapsed seconds" [1.538, 3.54, 4.542, 5.043, 7.046, 8.548, 10.551, 12.053, 13.554, 15.557, 16.057, 17.057, 19.06, 20.562, 22.064, 24.067, 25.569, 27.572, 29.074, 31.075, 32.577, 34.078, 36.08, 37.582, 39.584, 41.085, 42.586, 43.086, 44.589, 46.092, 48.094, 49.595, 51.597, 53.099, 54.6, 56.602, 58.105, 60.106]
y-axis "CPU percent" 0 --> 200
line [125.91, 105.82, 157.59, 117.82, 89.83, 109.82, 125.93, 55.86, 21.97, 3.99, 0, 0, 0, 3.99, 2, 69.95, 67.87, 45.97, 81.95, 97.9, 111.94, 115.73, 115.91, 105.88, 101.76, 77.99, 112, 113.94, 45.9, 131.91, 25.98, 0, 0, 115.9, 0, 123.85, 139.81, 133.86]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.037, 1.538, 3.54, 4.542, 5.043, 7.046, 8.548, 10.551, 12.053, 13.554, 15.557, 16.057, 17.057, 19.06, 20.562, 22.064, 24.067, 25.569, 27.572, 29.074, 31.075, 32.577, 34.078, 36.08, 37.582, 39.584, 41.085, 42.586, 43.086, 44.589, 46.092, 48.094, 49.595, 51.597, 53.099, 54.6, 56.602, 58.105, 60.106, 61.475]
y-axis "Memory MiB" 0 --> 500
line [13.95, 102.88, 117.81, 126.46, 143.66, 149.13, 137.28, 141.86, 139.15, 122.04, 121.11, 121.11, 121, 121.59, 121.59, 121.77, 128.06, 147.95, 135.73, 133.39, 235.26, 179.15, 209.52, 163.13, 154.45, 145.27, 144.72, 232.61, 251.26, 226.79, 232.9, 229.76, 233.74, 232.28, 154.49, 133.43, 161.09, 147.73, 167.82, 0]
line [10.38, 99.13, 114.07, 122.76, 140.15, 145.38, 133.53, 138.13, 135.38, 118.27, 117.34, 117.34, 117.23, 117.81, 117.81, 117.93, 124.24, 144.16, 132.37, 129.35, 231.43, 175.31, 205.7, 159.34, 150.61, 141.14, 140.88, 229.04, 247.52, 222.95, 229.07, 225.93, 229.91, 228.44, 150.65, 129.59, 157.29, 144.05, 164.11, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [1.037, 1.538, 2.539, 4.04, 5.043, 6.545, 8.046, 9.048, 10.548, 12.051, 13.054, 14.554, 15.554, 17.054, 18.557, 19.557, 21.058, 22.06, 23.563, 25.064, 26.067, 27.568, 28.569, 30.07, 31.572, 32.573, 34.074, 34.574, 35.575, 36.576, 38.078, 39.079, 40.58, 42.082, 43.084, 43.585, 44.586, 45.588]
y-axis "CPU percent" 0 --> 200
line [27.96, 117.87, 109.98, 139.76, 123.78, 145.71, 109.75, 119.9, 113.94, 91.84, 81.79, 52.02, 126.01, 123.96, 103.86, 119.87, 123.9, 37.93, 113.84, 97.92, 71.84, 17.98, 35.95, 123.85, 27.99, 13.99, 27.98, 0, 49.96, 11.99, 29.96, 43.97, 10, 77.89, 115.86, 153.81, 63.94, 125.66]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.037, 1.037, 1.538, 2.539, 4.04, 5.043, 6.545, 8.046, 9.048, 10.548, 12.051, 13.054, 14.554, 15.554, 17.054, 18.557, 19.557, 21.058, 22.06, 23.563, 25.064, 26.067, 27.568, 28.569, 30.07, 31.572, 32.573, 34.074, 34.574, 35.575, 36.576, 38.078, 39.079, 40.58, 42.082, 43.084, 43.585, 44.586, 45.588, 46.693]
y-axis "Memory MiB" 0 --> 500
line [13.98, 87.59, 102.34, 105.99, 137.98, 141.34, 161.35, 147.03, 142.01, 151.11, 135.3, 138.68, 128.52, 150.62, 140.06, 223.68, 179.62, 208.43, 137.41, 163.17, 136.59, 144.49, 139.23, 161.52, 244.39, 229.34, 225.45, 232.49, 232.49, 236.55, 234.04, 232.14, 232.55, 151.49, 146.21, 152.29, 170.43, 146.07, 161.88, 0]
line [10.35, 83.77, 98.55, 102.3, 134.18, 137.53, 154.44, 143.12, 138.17, 147.24, 131.47, 135.45, 124.7, 146.86, 136.22, 220.06, 175.52, 205.13, 133.56, 159.52, 132.73, 140.82, 134.44, 158.36, 240.55, 225.49, 221.62, 228.65, 228.65, 232.71, 230.19, 228.3, 228.79, 147.65, 142.36, 148.33, 167.99, 142.23, 158.06, 0]
Deterministic fixture · required contractThe fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.
Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking. |
Sequential Navigation Soak A/B✅ HEAD completed the 200-navigation resilience and memory observation. One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Common ancestor Session resilience
A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence. Process-tree memory
HEAD memory by 50-navigation quarter
Raw reports and per-navigation boundary samples: workflow run and full Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold. |
3d96be7 to
421b330
Compare

**Track:** Web Fetch (Browser Eval). Replaces part of #1584.Closes #2770.
Replaces part of #1584.
Problem.
moli fetch URL --wait domstablereturned while a parser-insertedasyncscript, a starting iframe or a dedicated Worker script was still loading, so the snapshot missed whatever they write. With each of those delayed 1.8-3 s, e.g.moli fetch http://127.0.0.1:PORT/async.html --wait domstable --dump htmlreturned after ~1.3 s withinitialinstead ofasync-ran.Reproduce (steps from #2770)
Use a server where
/delay?d=SEC&body=JSsleepsSECseconds and then returnsJSas JavaScript.Expected
async.html:async-ran, as Chrome--dump-domand moli's own--wait networkidleshow (3.55 s).frame.html: the child content, as in Chrome.worker.html:from-worker. This is moli's owndomstablecontract, since a worker script that loads quickly is waited for (0.40 s). Chrome's dump-dom does not wait for workers, so there is no Chromium reference for this case.Actual
async.html(classic andtype=module): returns after 1.25 s withinitial.frame.html: returns after 1.24 s without the child content.worker.html: returns after 0.39 s withinitial.For comparison,
domstabledoes wait correctly for afetch()with the same 3 s delay (3.40 s) and for scripts inserted from JavaScript.Change. In
runtime/page_dom.rs,advance_dom_stable_wait_turnonly treated post-DOMContentLoaded runtime script work, WebCrypto and OPFS as pending. It now also checks three existing load signals, as a separatepending_loads:has_post_domcontentloaded_load_delaying_runtime_work()for parser-inserted async scripts (madepub(crate)inscript_vm/post_parse_lifecycle.rs);has_pending_child_document_lifecycle()for starting iframes;has_loading_dedicated_workers()over the existing dedicated-worker loading count (script_vm/runtime_observability.rs).While any of them is true, the stability timer does not start, the same as for an in-flight
fetch(). They are deliberately not latched intosaw_post_domcontentloaded_runtime_work. A page whose async script or iframe loaded briefly therefore keeps the 350 ms base quiet window instead of switching to the 1200 ms runtime window.Verification.
Issue fixtures (local server, delays as in the issue),
--wait domstable --dump html --with-frames:initialasync-rantype=module, 3 s)async-ranasync-ran(already worked)srcdocsrcdocholdschild-doc-raninitialfrom-workerfetch_with_domstable_waits_for_async_scripts_iframes_and_workers(moli-core/tests/fetch_behaviors.rs, fixture routes inmoli-test-support/src/routes_wait.rs) covers all three loads with a 1.8 s delay.cargo nextest run -p moli -p moli-core -E 'test(domstable) | test(dom_stable)': 25 of 26 passed. The failure wascli_quiet_page_domstable_uses_remaining_best_effort_budget, which then passed 2 of 3 re-runs. That test leaves 250 ms of budget and is timing-sensitive on this loaded host (load average ~10). Against the same scenario (500 ms page,--timeout 750),origin/mainalso failed 1 of 10 runs, while this branch passed 10 of 10. The page has no async script, iframe or worker, sopending_loadsis false and the code path is identical to main.cargo fmt --allclean;cargo clippy -p moli-renderer-v8 --all-targets --all-features -- -D warningsclean. The earlier revision was also clippy-clean formoli-test-supportandmoli-core. Workspace clippy was not run locally.serialize_html_asyncnow takes&mut self, so the new test bindslet mut page. On the rebased debug build the issue fixtures giveasync-ran(3.41 s), the childsrcdocwithchild-doc-ran(2.24 s) andfrom-worker(2.22 s).fetch_with_domstable_waits_for_async_scripts_iframes_and_workerspasses;-p moli -p moli-core -E 'test(domstable) | test(dom_stable)': 25 of 26, the timing-sensitivecli_quiet_page_domstable_uses_remaining_best_effort_budgetagain failed once and then passed 4 of 5 re-runs (load average ~12). Clippy onmoli-renderer-v8,moli-coreandmoli-test-supportwith--all-targets --all-features -D warningsis clean.Cost. The extra wait happens only while a real parser-inserted async script, starting iframe or loading dedicated Worker is pending. It ends when that load finishes and is always bounded by the existing
--wait/--timeoutdeadline. A dedicated Worker whose script never finishes loading therefore makesdomstablewait until that deadline, the same as a hangingfetch()does today. On pages without such loads the three checks are constant-time boolean reads once per poll, and the quiet window is unchanged.Measured with
/usr/bin/time -lon debug builds oforigin/main(cbf4d01) and this branch, same profile. Runs alternate main and branch, and each figure is the median of 7:--wait domstablecaseThe long-delay pages take longer by design: each now waits for its load plus the 350 ms base quiet window, instead of returning before the content arrives.