Repository navigation
fix(resize-observer): deliver observations once per animation frame - #2818
lanyue-llk wants to merge 7 commits into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 546cf70 (diffed against #2810's head 3397793)
Changes needed (1)
-
ResizeObserver can run before
requestAnimationFramecallbacks of the same frame. Seeresize_observer_runtime.rs:770-776(schedule_resize_observer_frame) andhost/timers.rs:690-696. The RO task and each rAF callback are separate timers. Each one'srun_atisInstant::now() + ceil(target - now), andTimerScheduler(moli-time/src/timers.rs:42-48) orders them byrun_at.ceilkeeps the delay at 16 ms for any call made less than 1 ms after the frame's timestamp was fixed, so the timer queued first fires first.Failure scenario: a script runs
ro.observe(el); requestAnimationFrame(() => { log.push('raf'); el.style.width = '200px'; });. This branch runs the RO task first: it logsrowith the old size, thenraf, then a second RO delivery one frame later. The rendering-update order in the spec, which Chrome follows, is rAF then RO in the same frame:raf, then oneroalready showing 200px.Related:
finish_animation_frame_callback_batchclears the pending frame timestamp at the first rAF callback. So anobserve()or resize inside a rAF callback is delivered a whole frame late, not in that frame. That means the PR body's "joins the same frame" holds only for timing. It does not hold for ordering.Smallest fix: make the RO task sort after every rAF callback queued for that frame. The simplest version is to schedule it at
delay_ms + 1:ceilputs all same-frame rAF deadlines within 1 ms of each other, so this keeps it behind them. A more exact option is to rundeliver_resize_observer_framefrom the end of the frame's rAF batch whenever one is pending. Either way, add a test that logsraf,rofor observe-then-rAF.
Other focus points, checked with no finding:
- Zero cost and idle. The timer is queued only by
queue_resize_observer_deliverywhen the queue goes from empty to non-empty (resize_observer_runtime.rs:761-766). That happens only for observers with targets after anobserve()or a DOM mutation. The queue is drained before any callback runs, so an idle page with an observer schedules nothing. Each mutation burst costs at most one 16 ms task per Window. There are no perpetual wakeups. --wait domstable/networkidle. A queued delivery is a short timer, comparable to a single rAF, so it never trips the long-pending-timeout path. A true feedback loop keeps changing the DOM and is bounded by the fetch deadline at 60 Hz. Before this PR it spun until the watchdog fired, so this is strictly better.- Child frames. The queue slot, frame timestamp, timer owner and delivery context are all taken from the same current global, so each document keeps its own queue.
- Tests. The 7 adjusted tests keep their expected values and only advance timers before asserting. The new test fails on the base, which logs
first,second,microtaskand delivers inside the script checkpoint. - Size. About 150 non-test lines, reusing the existing
ResourceTimingBufferFullnative-task pattern. That is proportional, and the native task is required for the per-callback checkpoint. - CI was still pending at review time (Build release, Clippy, Nextest, CDP smoke).
- Picture: pending.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 95184fa (round 2, diff against #2810's fix/resize-observer-layout)
No blocking findings
The round-1 ordering problem is fixed for the normal cases. RO frame delivery, gather-then-broadcast with a checkpoint per callback, skipping disconnected observers and the native ResizeObserverFrame task all look right. Default path cost is unchanged because nothing is scheduled without a queued observer.
Non-blocking notes:
-
resize_observer_runtime.rsschedule_resize_observer_frame(delay_ms + 1): the margin holds in exact arithmetic. DOM time is floored to 0.1 ms, so every same-frame rAF is due before T+1 and RO is due at T+1 or later. Two things can still put a rAF after RO, though:- FP rounding can turn an integer
T - nowintok + 1e-13, soceiladds a whole ms to that rAF. - The gap between the
SystemTimeread innext_animation_frameand the laterInstant::now()inschedule_afterdiffers per call.
A simulation of
observe()followed byrequestAnimationFrameat a random later point in the same frame gave about 1.5e-5 inversions per pair from rounding alone. The effect is one frame with the oldro,raforder. The new test can't hit this, because both calls land on the same 0.1 ms tick. The smallest hardening isdelay_ms.saturating_add(2), or computing the delay from(T - now)rounded to the 0.1 ms grid beforeceil. Your call. - FP rounding can turn an integer
-
Body, "Limitation": the resize is not always a frame late. It is late only when the RO queue is empty at the time. If an RO frame task is already pending for this frame, for example from an earlier
observe(), an observer queued in a rAF callback joins it and is delivered in the same frame. Suggest "usually delivered one frame later".
CI: Format, Node, Python and Windows pass; Nextest, Clippy, CDP smoke and the builds were still pending at review time. Picture matches the body (feedback loop, ordering fixtures, flow, cost). It doesn't show the new rAF-before-RO step or its test, which is fine.
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. |
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" [2.039, 4.042, 5.545, 7.547, 9.549, 11.552, 13.055, 14.056, 15.058, 17.06, 19.061, 20.562, 22.566, 24.568, 26.57, 28.072, 30.075, 32.077, 34.08, 35.583, 37.585, 38.086, 39.588, 41.589, 43.091, 45.094, 47.096, 49.098, 50.6, 52.602, 54.606, 56.609, 58.11, 60.113, 62.115, 64.118, 65.62, 67.121]
y-axis "CPU percent" 0 --> 200
line [105.84, 91.86, 143.68, 81.96, 67.94, 121.66, 1.99, 0, 0, 2, 0, 10, 9.99, 11.99, 10, 61.84, 79.79, 21.94, 33.95, 101.94, 99.76, 107.79, 109.81, 45.95, 125.89, 103.94, 11.99, 127.86, 109.72, 119.84, 37.89, 25.98, 2, 0, 127.83, 2, 31.96, 147.73]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.037, 2.039, 4.042, 5.545, 7.547, 9.549, 11.552, 13.055, 14.056, 15.058, 17.06, 19.061, 20.562, 22.566, 24.568, 26.57, 28.072, 30.075, 32.077, 34.08, 35.583, 37.585, 38.086, 39.588, 41.589, 43.091, 45.094, 47.096, 49.098, 50.6, 52.602, 54.606, 56.609, 58.11, 60.113, 62.115, 64.118, 65.62, 67.121, 67.492]
y-axis "Memory MiB" 0 --> 500
line [13.93, 108.63, 112.16, 131.72, 136.99, 125.83, 135.61, 136.49, 135.49, 135.49, 135.47, 135.58, 134.94, 134.96, 135.77, 135.12, 133.56, 146.04, 130.13, 127.4, 131.49, 231.86, 243.09, 191.85, 138.66, 132.81, 141.03, 133.83, 233, 225.46, 234.44, 234.58, 232.82, 232.99, 152, 163.23, 133.57, 135.43, 167.08, 0]
line [10.61, 105.14, 108.81, 128.08, 134.77, 122.24, 132.12, 132.98, 131.98, 131.98, 131.89, 131.98, 131.34, 131.36, 132.17, 131.53, 129.96, 142.44, 126.53, 123.89, 127.88, 228.28, 239.07, 188.29, 134.88, 129.29, 137.54, 130.33, 229.57, 221.97, 230.96, 231.1, 229.33, 229.51, 148.52, 159.66, 129.91, 131.95, 163.74, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [2.039, 4.042, 4.542, 6.544, 9.047, 11.05, 13.053, 15.556, 17.558, 20.062, 22.065, 24.067, 26.572, 28.574, 30.577, 33.079, 35.08, 37.585, 39.587, 41.589, 44.093, 46.095, 48.598, 50.601, 52.604, 55.108, 57.111, 59.614, 61.117, 61.617, 63.619, 66.122, 68.124, 70.129, 72.632, 74.635, 75.636, 77.137]
y-axis "CPU percent" 0 --> 200
line [129.61, 85.8, 133.92, 139.86, 135.87, 49.93, 0, 9.99, 9.99, 0, 1.99, 0, 9.98, 7.98, 11.99, 2, 64.02, 5.97, 70.03, 103.77, 39.92, 103.96, 107.97, 103.92, 59.89, 111.78, 89.89, 77.91, 101.69, 137.79, 59.93, 39.96, 2, 43.86, 9.99, 141.82, 159.77, 99.9]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.036, 2.039, 4.042, 4.542, 6.544, 9.047, 11.05, 13.053, 15.556, 17.558, 20.062, 22.065, 24.067, 26.572, 28.574, 30.577, 33.079, 35.08, 37.585, 39.587, 41.589, 44.093, 46.095, 48.598, 50.601, 52.604, 55.108, 57.111, 59.614, 61.117, 61.617, 63.619, 66.122, 68.124, 70.129, 72.632, 74.635, 75.636, 77.137, 78.722]
y-axis "Memory MiB" 0 --> 500
line [13.62, 104.27, 115.06, 133.24, 143.22, 149.42, 146.62, 140.84, 136.78, 136.77, 136.5, 136.5, 136.54, 136.54, 136.56, 136.59, 136.59, 148.27, 124.81, 128.7, 122.8, 132.95, 134.55, 182.5, 205.3, 152.89, 163.23, 141.57, 177.19, 244.54, 219.03, 231.45, 235.47, 232.39, 237.26, 135.51, 161.9, 168.96, 159.61, 0]
line [10.22, 100.67, 111.46, 129.56, 139.68, 146.44, 143.05, 137.27, 133.22, 133.22, 133, 132.88, 132.9, 132.93, 132.98, 132.97, 133.02, 142.69, 121.2, 125.1, 119.11, 129.26, 130.96, 178.89, 201.57, 149.18, 155.31, 137.93, 173.55, 240.73, 213.54, 227.15, 231.9, 228.86, 233.68, 131.93, 158.38, 165.39, 156.08, 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. |
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.003149%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 — ✅ 120/120 groups passed; 1,798 scenariosWorkers: 4 · cumulative group time: 586.00 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. |
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 878cacb (diff against #2810's fix/resize-observer-layout)
Changes needed (1)
-
--evaland--dump semantic_tree[_text]still lose content written by a ResizeObserver; regression vs #2810.moli-renderer-v8/src/runtime/page_commands.rs:863-894flushes the pending frame only forRenderPageDump,SerializeDocument,CaptureScreenshotandPrintToPdf. The fetch CLI reads the DOM through two other commands right after readiness:EvaluateExpression*(page_commands.rs:46-75, reached frommoli/src/app.rs:205-218) andAccessibilityTreeNodes(moli/src/fetch_dump/semantic.rs:16-36). Neither gets the flush. Repro:<div id=t style='width:30px;height:10px'></div><p id=o></p><script>new ResizeObserver(()=>{o.textContent='ROTEXT'}).observe(t)</script>as a data: URL. Results from a debug build of this head, with v1.1.23 (microtask delivery, same as #2810) in brackets:--eval 'o.textContent'(default--wait done):""[ROTEXT]- same with
--wait load,--wait domcontentloaded, or--layout:""[ROTEXT] --dump semantic_tree_text, with or without--layout: no ROTEXT [ROTEXT]--dump html,--dump markdown,--eval … --dump html,--wait domstable,--wait networkidle,--delay-ms 50: ROTEXT, OK
This also makes a single invocation inconsistent:
--evalreports the pre-callback DOM, then--dump htmlshows the callback's output. Web Fetch runs depend on--eval. Smallest fix: run the one-round flush once, where fetch readiness completes (end ofReadinessPlan::wait_for_page,moli/src/app/readiness.rs:86, or one page command issued right after it inapp.rs). Do not add it per command. That single call covers eval, the semantic tree and every dump. Putting the flush onEvaluateExpressioninstead would run a frame before every CDPRuntime.evaluate, which is not frame behavior. The capture-command flushes can stay for CDP clients. Add an--evalcase and asemantic_tree_textcase tocli_dumps_include_content_written_by_resize_observers.
Checked, no finding:
- Bounded:
deliver_resize_observer_framedrains the queue before it calls any callback. Gathering runs no JS. An observer re-queued by a callback lands in a fresh queue with its own frame timer, so the flush is exactly one round and cannot loop. Each callback goes throughinvoke_and_report, followed by a microtask checkpoint, and runs beforerender_page_dumpor the serializer starts, so nothing re-enters them. A callback that throws is reported and the dump continues.with_current_main_world_scopenever creates a main world. - Child frames:
--with-frames --dump htmlwith an RO inside ansrcdociframe contains the child's output on this head, as on v1.1.23.--with-frames --dump markdownmisses it on both (0/0), so that gap predates this PR. Acceptable as the disclosed limit. - Cost: with nothing queued, the flush is one handle/context scope and one empty-queue pop. The original frame timer then fires as a no-op. The before/after dump timings in the body are plausible.
- CI: Format, Node, Python and Windows pass. Nextest, Clippy, Build and CDP smoke were still pending at review time.
- Picture: matches the body's main change, ordering and cost. It does not show the pre-dump flush, which is fine.
lanyue-llk
left a comment
There was a problem hiding this comment.
Verification of fdacfc0 (follow-up to the round-3 review)
No blocking findings
The round-3 finding is fixed. One RO delivery round now runs where moli fetch readiness completes (moli/src/app/readiness.rs), so --eval and --dump semantic_tree[_text] include content written by observer callbacks, as on #2810 and v1.1.23. CDP Runtime.evaluate does not run a frame, and the capture-command flushes are skipped inside a debugger pause (nested_main_dispatch_active()).
I re-ran the reviewer's repro (<p id=o> filled with ROTEXT by a ResizeObserver) on a build of this head. --eval 'o.textContent' returns ROTEXT with --wait domcontentloaded, load and done, and also with --layout. semantic_tree_text and --dump html both contain ROTEXT. The delta since 878cacb (12 files, +117/−11) is limited to the readiness flush, the per-Window frame-task flag that prevents doubled timers, and the nested-dispatch guard.
3397793 to
c7fd35f
Compare
fdacfc0 to
9a87172
Compare
c7fd35f to
14bb8f7
Compare
9a87172 to
d880a4c
Compare
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of d880a4c (own commits only: fix/resize-observer-layout...fix/resize-observer-frame)
Changes needed (1)
- Export commands now run page script, which breaks #2836's contract and duplicates the readiness flush. See
moli-renderer-v8/src/runtime/page_commands.rs:864(RenderMarkdown) and:870(SerializeDocument).- Contract. #2836 makes page HTML, the JSON
htmlfield and MHTML one projection of the live DOM, with no JavaScript, no frame loads and no yielding. This PR puts author callbacks and microtask checkpoints in front of that projection, inside the same command. The serializer function is still pure, but the export command is not.SerializeDocumentis also still listed under "read native document/agent state without entering a new V8 scope" (devtools/command/nested.rs:72), and that comment is no longer true. The newNESTED_MAIN_DISPATCHthread-local (runtime/nested_main.rs:26) exists only to work around this. The flush also runs throughwith_current_main_world_scope(script_vm/rendering_update.rs:83). That helper is documented as "not a browser task boundary" (script_vm/context_scope.rs:67), so a callback's task-end runtime follow-up, such as a queued navigation or child-frame sync, never has an owner. The PR body says the same about the sibling command. - Chromium. CDP
Page.captureSnapshot(moli-protocol/src/domains/page/native.rs:109,domains/page/capture.rs:172) now delivers ResizeObserver callbacks. Chromium's MHTML capture does not run an animation frame. The PR itself saysRuntime.evaluatedoes not flush because "CDP clients drive frames themselves", so the two CDP paths now disagree. - Redundant, and it breaks frame pacing.
moli/src/app/readiness.rs:110already runs the same one-round flush after readiness for every--waitmode, before any dump or--eval. A CLI dump therefore delivers twice with no frame in between: once at readiness and once atSerializeDocument/RenderMarkdown. On the #2795 feedback-loop fixture (a callback togglesdisplay),moli fetch --dump htmlruns two callbacks back to back. The dumpeddisplaythen depends on how many export commands ran, not on frames. Each CDPPage.captureSnapshotcall also drives one extra delivery, so a polling client sets the loop's rate instead of the frame timer. The before/after table in the body ("this PR before this fix 3a58b96: missing") was measured before the readiness flush existed. It does not show that the export-command flush is still needed for the CLI. - Smallest fix. Remove
run_pending_resize_observer_frame()from theRenderMarkdownandSerializeDocumentarms. Keep the readiness flush (one explicit step, CLI only). Keep theCaptureScreenshot/PrintToPdfflush only if you want screenshot parity, since Chromium's screenshot does produce a frame. Inmoli-core/tests/web_apis.rs:1471, wait one frame afterrunGeometryProbe(), as a CDP client must in Chromium. For example, evaluatenew Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))with await, or callrun_pending_resize_observer_frame_async(). Do not make the export do it.
- Contract. #2836 makes page HTML, the JSON
Checked, no finding:
- Pause and re-entrancy. The only nested consumer is
claim_for_pause→dispatch_nested_main_page_command, and it sets the guard.RenderMarkdown/PrintToPdf/RunPendingResizeObserverFrameare V8-entering and are never nested-dispatched.DOM.getOuterHTML/OuterHtmlForDocument/OuterHtmlForNodeand the Inspector shadow profiles are untouched. - Cost without observers. One V8 context entry and a private-slot pop per export command. It is a no-op when no main world exists.
- CI. Clippy, Format, the harness tests and Windows pass. Nextest, the CDP smoke test and the release builds were still pending at review time.
lanyue-llk
left a comment
There was a problem hiding this comment.
Follow-up review of 17ba647
No blocking findings. Finding 1 from the previous review is resolved.
- The
RenderMarkdownandSerializeDocumentarms inpage_commands.rsare now byte-identical to the base (14bb8f7718). HTML, MHTML and Markdown exports no longer run any observer delivery. This matches #2836: an export is a projection of the live DOM and runs no JavaScript. CDPPage.captureSnapshotno longer drives deliveries either. - The CLI now delivers once, at readiness (
readiness.rs:110). The extra back-to-back delivery before an export is gone. - The
NESTED_MAIN_DISPATCHguard is still needed, and the reason given for it is correct.CaptureScreenshotis classified asPageAgent(devtools/command/nested.rs:75), soclaim_for_pausecan claim it and run it throughdispatch_nested_main_page_command. Without the guard, the screenshot flush would run page script during a debugger pause.PrintToPdfandRunPendingResizeObserverFrameare V8-entering commands and are never dispatched while paused. - Keeping the flush before a screenshot or PDF matches Chromium, which produces a frame before capture.
- In
web_apis.rs:1484the test now callsrun_pending_resize_observer_frame_async()explicitly, which stands in for letting a frame pass. That is the right place for this step. The expectations are unchanged. - The doc comment in
rendering_update.rsnow matches the code. No new issues found in this delta.
CI was still running when I checked; Format and Node harness had passed.

**Track:** Web Fetch (Browser Eval). Replaces part of #1593.Part of #2795. Stacked on #2810: the base is
fix/resize-observer-layout, so this diff contains only the delivery change.Problem. ResizeObserver callbacks ran as host microtasks scheduled on every
observe()and DOM mutation, not in a rendering update. This caused three problems:displayon its target) ran ~15,000 callbacks in one frame until the watchdog terminated it, burning about 8 s of CPU per fetch.first'sPromise.resolve().then(() => second.disconnect())ran aftersecondhad already been called.queueMicrotaskwork queued by the same script.Reproduce (steps from #2795)
Each page records into globals, and the client reads them after 1.6 s:
Promise.resolve().then(()=>{order.push('microtask'); second.disconnect()}).new ResizeObserver(()=>log.push('ro:mt='+mt)).observe(t); queueMicrotask(()=>mt=true).a,bandc. Observerfirstwatchesaand observersecondwatchesb;first's callback callssecond.observe(c).<div id=node style="width:50px;height:20px">x</div>, with an observer callback that togglesnode.style.displaybetween''and'none', plus a rAF frame counter and anerrorlistener.Expected (Chromium; HTML "update the rendering" and the ResizeObserver spec)
["first","microtask"]["ro:mt=true"]["first","second:b","error","second:c"]errorevent per frame, with message "ResizeObserver loop completed with undelivered notifications." (trusted, not bubbling, cancelable,filename= the document URL;window.onerroris called). After 1 s: 144 callbacks, 144 errors and 145 frames.Actual
["first","second","microtask"]["ro:mt=false"]["first","second:b,c"], with no error eventChange.
context_bootstrap/resize_observer_runtime.rs: queuing an observer no longer schedules a microtask. The first observer queued for a Window schedules one delivery for that Window's next animation frame.deliver_resize_observer_framethen gathers the observations of every queued observer first, and only after that calls each observer's callback, with a microtask checkpoint after each. An observer disconnected by an earlier callback or its microtasks is skipped. Changes made during a delivery are picked up at the next frame, so a feedback loop runs one delivery per frame, as withrequestAnimationFrame.host/timers.rs: the delivery is a small native timer task,ScheduledTimerCallback::ResizeObserverFrame, modelled on the existingResourceTimingBufferFulltask. It runs outside any JS call, which is required for the per-callback checkpoint; an internal JS-function timer suppresses that checkpoint.window_host.rs:next_animation_frameis the rAF timestamp/delay computation, extracted unchanged, so RO delivery joins the same frame cadence and shared timestamp asrequestAnimationFrame.requestAnimationFramecallback of that frame, as in the rendering update:observe(el); requestAnimationFrame(() => el.style.width = '200px')givesraf, ro. Limitation: anobserve()or resize made inside a rAF callback is usually delivered one frame later (it joins the same frame when an RO delivery is already pending), because moli has no single end-of-frame step to hook into.runtime/page_commands.rs+script_vm/rendering_update.rs: because delivery now waits for the frame timer, output read right after readiness could miss what an observer writes.CaptureScreenshotandPrintToPdftherefore first run a pending RO frame delivery once (run_pending_resize_observer_frame), through the same gather/broadcast/checkpoint path, as the frame Chromium produces for a screenshot would. Page exports do not:RenderMarkdownandSerializeDocument { options }(since refactor(html): serialize page exports without DOM copies #2836 the single path for page HTML, the JSONhtmlfield and MHTML) stay a pure projection of the live DOM and never run page script, as in Chromium, wherePage.captureSnapshotdoes not run an animation frame. The flush is one round, top-level Window only; a feedback loop's next delivery is still paced by the frame timer. With nothing queued it does nothing, and it never creates a main world.moli/src/app/readiness.rs+Page::run_pending_resize_observer_frame_async(RendererPageCommand::RunPendingResizeObserverFrame): CLIfetchruns the same one-round flush once, when readiness completes, for every--waitmode, before any dump or--eval. This is the one step that makes--dump html|json|markdown|semantic_tree[_text]and--evalinclude what observers wrote. The command does not refresh page state or follow a queued navigation.Runtime.evaluateand the export commands do not flush, so CDP clients let a frame pass themselves, as in Chromium;secondary_webapis_cover_file_file_list_and_resize_observer_basicsnow runs the pending frame afterrunGeometryProbe()before reading the page. The command is classified as a V8-entering command for nested dispatch.frame:width:ms:1:100:39, 2:0:50, 3:100:70, …).runtime/nested_main.rs), the flush is skipped (nested_main_dispatch_active()), so a screenshot taken while paused (CaptureScreenshotcan be nested-dispatched) never runs page script; the frame timer delivers after resume. There is no nested-dispatch test nearby to extend;test(nested) | test(pause) | test(resize_observer)passes.Verification. Triage fixtures, debug builds,
moli fetch URL --delay-ms 300 --eval 'JSON.stringify(OUT())':queueMicrotaskafterobserve)["ro:mt=false"]["ro:mt=true"]["ro:mt=true"]["first","second","microtask"]["first","microtask"]["first","microtask"][100][100]frame:width:ms1:100:48, 3:0:75, 4:100:94, 5:0:112, …resize_observer_delivers_at_the_frame_with_a_checkpoint_per_callback. It checks nothing is delivered in the script's microtask checkpoint, and that the first callback's microtask disconnects the second observer before it is called.--delay-ms), an observer that setsdata-observed="yes"and writesROTEXT, current head 17ba647: the text is present in--dump html|json|markdown|semantic_tree_text, in--layout --dump html, and in--eval 'o.textContent'at--wait-until domcontentloaded/load/donewith and without--layout, all through the single readiness flush. Before the readiness flush and capture flushes (3a58b96) the dumps lacked it andro2.html --layoutwas empty; nowROW-0 (h=200)…ROW-4 (h=200).Page.captureSnapshot(MHTML) onmoli serve, called right afterPage.navigatereturns: the observer output is not yet in the snapshot. A second snapshot 200 ms later contains it, delivered by the frame timer. The export itself no longer drives deliveries.display) with--dump htmlnow shows 2 callbacks (frame timer plus the one readiness flush); the export adds none.cli_dumps_include_content_written_by_resize_observers(moli/tests/fetch_cli.rs) covers the html dump (plain and--layout),--evalat the three--wait-untilmodes with and without--layout, and--dump semantic_tree_text.resize_observer_delivery_follows_the_frames_animation_callbacks(observe, then rAF →raf,ro). It fails asro,rafwithout the extra delay.observe()now advance the timer task first withadvance_timers_until_deadline_for_test. Their expected values are unchanged.cargo nextest run -p moli-renderer-v8 -E 'test(resize_observer) | test(observer_callbacks) | test(ondemand_ro) | test(real_ro) | test(animation_frame) | test(intersection) | test(timer)': 159 passed.cargo fmt --allclean;cargo clippy -p moli-renderer-v8 --all-targets --all-features -- -D warningsclean (workspace clippy not run locally).cargo fmt --allclean;cargo clippy -p moli-renderer-v8 -p moli-core -p moli --all-targets --all-features -- -D warningsclean; renderer filter above plustest(serialize) | test(nested) | test(pause) | test(lazy_main_world) | test(markdown): 524 passed;-p moli -E 'test(resize_observer) | test(cli_dump_html) | test(render_page_dump) | test(mhtml) | test(markdown)': 34 passed;-p moli-core --test web_apis: 163 passed. Repro: microcheck["ro:mt=true"], microdisc["first","microtask"].Cost. Pages without a ResizeObserver never schedule anything. A page with observers gets at most one native delivery task per Window per animation frame, and only while observations are queued. A feedback loop now costs one delivery per frame instead of spinning until the watchdog fires. Debug builds of main cbf4d01 and this branch, same profile,
/usr/bin/time -l:hidefb_nocap.html --delay-ms 1000 --timeout 10000), 3 runsResizeObserver callbackwas terminated"ro1.html), median of 7--layout --delay-ms 500, median of 7Dump cost with the earlier pre-dump export flush (now removed from exports; kept for screenshot/PDF) (debug, alternating runs, median of 7): ordinary article
--dump html0.10 → 0.09 s; ordinary--layout --dump screenshot0.99 → 0.99 s; observer pagero1.html0.07 → 0.07 s. The feedback loop with--delay-ms 1000is unchanged: 53 callbacks over 55 frames, 0.28-0.30 s user CPU.After the readiness flush (debug): ordinary article
--dump html0.08 s and--eval0.08 s (5-run medians). The feedback loop with--delay-ms 1000gives 56 callbacks over 56 frames at 0.29 s user CPU.