Repository navigation
fix(style): resolve rem units against the root element font size - #2771
lanyue-llk wants to merge 1 commit into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 89b22cd
No blocking findings
What I checked, against origin/main:
- Root cause. Moli has no full Stylo traversal. All three resolution paths (
resolve_element_styles,prepare_style_observation_targets,materialize_ancestor_styles_for_resolution) are the onlyresolve_style/StyleResolverForElementcallers, and they all go throughpublish_resolved_element_styles. So the Device update frommatching.rs(set_root_style, root font size, root line height, root metrics when used) now runs on every route. The root's ownremcomes from the cascade (initial size) and not from the Device, so the root resolving against the old Device value does no harm. - Child documents and iframes.
world_for_documentreturns a per-Document world, and each world has its ownRetainedStyleSystemwith its own Stylist, Device androot_style.IS_ROOT_ELEMENT_STYLEis set only whenis_root()holds (parent node is a Document,moli-selector/src/stylo/style_traversal.rs:2363). An iframe's<html>therefore updates only its own Device, and nothing leaks across documents. - Shadow roots. Children of a shadow root are not
is_root(). Theirtraversal_parentchain reaches the document root, so they share the Document's Device, which matches the spec (remuses the document root). - Stale descendants. A root style change makes the root a lazy invalidation root, so its whole subtree carries the new generation. Any later read re-resolves the root first, and
force_descendants/inherited_changethen re-resolves the descendants along the path. The test'ssgoing from 20px to 40px exercises this. After a Device rebuild,set_deviceinvalidation re-resolves the root wherever media rules change it. Otherwise the replayedroot_styleis still the root's current published style. - Stale or leaked
root_style. The field is per-Document and is overwritten on every root publish. A full rebuild (build_retained_style_system) resets it toNonetogether with clearing element data. A Device rebuilt in place replays it, andcomputed.rspublish_resolved_element_stylesrefreshes it the next time the root is resolved. - Cost. The added work is a few atomic stores and one line-height calculation (servo
calc_line_heightis arithmetic), and it runs only when the root element resolves. Font metrics are queried only whenused_root_font_metrics()is set. Memory grows by one Arc clone of the root style per Document. - Test. Without the fix,
sreads 32px andtreads 48px, so the test fails on main. The expected values match Chromium. - CI. Format, Clippy, Nextest, Build release (HEAD), CDP smoke (Chromium), Python/Node harness and Windows storage pass. The differential, PDF, WebDriver, Spider and benchmark jobs were still pending at review time.
Pending (others are adding these): the body's Cost section and its picture (only the <!-- picture --> placeholder is there now).
|
CI note: the failing "Native PDF rendering and links" job is not caused by this PR. It is a regression on |
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.000291%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,754 scenariosWorkers: 4 · cumulative group time: 489.43 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.037, 1.537, 3.039, 4.542, 5.544, 7.046, 8.547, 10.049, 11.551, 13.053, 14.554, 15.556, 17.057, 18.56, 20.062, 21.563, 23.065, 24.567, 26.069, 27.071, 28.572, 30.074, 31.576, 33.078, 34.581, 36.083, 36.583, 37.084, 38.586, 40.087, 41.587, 43.09, 44.591, 46.093, 47.094, 48.096, 48.596, 50.099]
y-axis "CPU percent" 0 --> 200
line [0, 4, 105.85, 139.7, 127.63, 99.76, 123.85, 107.83, 121.94, 87.94, 87.98, 3.99, 53.99, 83.97, 119.88, 121.85, 119.89, 39.96, 107.86, 93.75, 69.92, 29.98, 57.95, 123.85, 17.96, 129.66, 23.98, 25.98, 55.95, 29.97, 2, 29.96, 7.99, 13.99, 127.78, 163.69, 113.89, 141.57]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.036, 1.037, 1.537, 3.039, 4.542, 5.544, 7.046, 8.547, 10.049, 11.551, 13.053, 14.554, 15.556, 17.057, 18.56, 20.062, 21.563, 23.065, 24.567, 26.069, 27.071, 28.572, 30.074, 31.576, 33.078, 34.581, 36.083, 36.583, 37.084, 38.586, 40.087, 41.587, 43.09, 44.591, 46.093, 47.094, 48.096, 48.596, 50.099, 51.364]
y-axis "Memory MiB" 0 --> 500
line [13.63, 57.1, 63.61, 121.55, 126.23, 140.96, 143.95, 160.04, 156.23, 159.84, 126.5, 152.75, 122.61, 125.47, 154.35, 160.46, 173.07, 194.64, 145.68, 161.68, 154.56, 147.09, 139.25, 156.21, 233.2, 225.37, 232.93, 234.59, 230.58, 234.35, 230.02, 230.08, 150.41, 148.21, 136.59, 155.11, 142.59, 152.63, 157.27, 0]
line [10.31, 53.63, 60.15, 118.02, 121.46, 137.56, 139.77, 155.97, 152, 156.32, 122.98, 149.38, 119.1, 121.93, 150.85, 156.96, 169.55, 191.19, 140.77, 158.1, 151.04, 143.64, 135.75, 152.72, 229.69, 221.85, 229.42, 231.08, 227.06, 230.83, 226.5, 226.56, 146.89, 144.7, 131.97, 151.64, 139.07, 149.12, 153.84, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [1.037, 1.538, 3.04, 4.041, 4.541, 6.041, 7.542, 9.042, 10.544, 12.046, 14.049, 15.552, 17.055, 18.556, 20.056, 21.557, 23.059, 24.56, 26.062, 27.564, 29.066, 30.568, 32.07, 33.57, 35.072, 36.572, 38.073, 39.574, 41.576, 43.079, 44.581, 46.083, 47.584, 49.086, 50.589, 51.591, 52.09, 53.593]
y-axis "CPU percent" 0 --> 200
line [0, 25.94, 113.99, 91.85, 139.86, 127.99, 102.01, 128, 137.69, 73.97, 13.97, 5.99, 151.58, 0, 14, 85.82, 107.88, 102.02, 101.89, 69.9, 102.05, 95.9, 99.9, 15.99, 35.98, 117.96, 61.97, 99.81, 25.99, 1.99, 27.93, 40, 13.98, 0, 115.84, 153.82, 112.03, 75.95]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.037, 1.037, 1.538, 3.04, 4.041, 4.541, 6.041, 7.542, 9.042, 10.544, 12.046, 14.049, 15.552, 17.055, 18.556, 20.056, 21.557, 23.059, 24.56, 26.062, 27.564, 29.066, 30.568, 32.07, 33.57, 35.072, 36.572, 38.073, 39.574, 41.576, 43.079, 44.581, 46.083, 47.584, 49.086, 50.589, 51.591, 52.09, 53.593, 55.055]
y-axis "Memory MiB" 0 --> 500
line [13.6, 57.71, 87.41, 121.53, 132.34, 139.08, 149.68, 135.78, 146.93, 137.2, 160.43, 118.38, 117.12, 146.12, 118.41, 118.12, 136.94, 129.87, 206.13, 184, 132.39, 166.36, 136.81, 141.02, 130.8, 134.89, 245.39, 226.86, 231.83, 229.02, 233.3, 231.73, 239.27, 133.75, 132.58, 167.11, 161.72, 146.18, 145.67, 0]
line [10.24, 54.18, 83.88, 118.27, 128.82, 135.66, 146.11, 132.18, 143.38, 133.64, 157.96, 114.81, 113.55, 142.56, 114.85, 114.55, 133.43, 126.33, 202.58, 180.43, 128.82, 163.26, 133.22, 137.43, 127.23, 130.18, 241.83, 223.31, 228.33, 225.45, 229.74, 228.17, 235.54, 130.18, 129.01, 163.55, 158.22, 142.63, 141.98, 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. |
471c1ed to
1b89e15
Compare

**Track:** Trajectory Replay (Browser Eval). Replaces part of #756.Closes #2761.
Problem.
rem(andrlh) always resolved against the 16px default, ignoring the root element's font size, so any page usinghtml{font-size:62.5%}laid out at the wrong scale in computed style, geometry, screenshots and PDF.moli fetch --layout 'data:text/html,<style>html{font-size:10px} %23s{width:2rem;height:1px}</style><div id=s></div>' --eval 'JSON.stringify({w:getComputedStyle(s).width,r:s.getBoundingClientRect().width})'printed{"w":"32px","r":32}; Chromium prints{"w":"20px","r":20}.Reproduce (steps from #2761)
Expected (Chromium)
{"w":"20px","r":20}. Afterdocument.documentElement.style.fontSize = "20px", the width becomes 40px.Actual
{"w":"32px","r":32}. After the root font-size change it is still 32px, even thoughgetComputedStyle(document.documentElement).fontSizereports20px.Change. Stylo updates the Device's root font size, line height and root style only during a full traversal (
matching.rs); Moli resolves elements one at a time withresolve_style, so the Device kept its defaults.publish_resolved_element_styles(style_engine/computed.rs), which every resolution path already goes through, now mirrors that update when it publishes the root element's style, using a smallsynchronize_root_style_devicehelper (style_engine/retained.rs, taken from the closed #756). The retained style system remembers the last root style (state.rs) and replays it onto a rebuilt Device after a viewport/environment change, so elements resolved afterwards do not fall back to 16px.Verification.
{"w":"32px","r":32}. This branch:{"w":"20px","r":20}.<script>document.documentElement.style.fontSize="20px"</script>), thens.getBoundingClientRect().width: v1.1.23[32], this branch[40].computed_size_rem_lengths_follow_root_font_size_across_device_rebuildscovers the initial value, a later root change and a new element after a viewport-driven Device rebuild.cargo fmt --allclean;cargo clippy -p moli-renderer-v8 --all-targets --all-features -- -D warningsclean (workspace clippy not run locally).cargo nextest run -p moli-renderer-v8 -E 'test(computed_size) | test(registered_properties) | test(/style_engine::tests::lifecycle/)': 106 passed.moli fetch --eval, changing the root size inside the--evalexpression and then reading geometry still returns the previous layout. The same happens fors.style.width="50px", so it is a separate stale-layout behaviour of--evaland not part of this fix.Cost. The added work is one
ComputedValueFlags::IS_ROOT_ELEMENT_STYLEcheck per published element style. The Device sync and the retainedArcclone happen only when the root element's style is published, and the replay happens only on a Device rebuild. No new per-element state is kept: there is one retainedArc<ComputedValues>per Document.Measured with
/usr/bin/time -lon debug builds oforigin/main(cbf4d01) and this branch, same profile. Each figure is the median of 5 runs, with the two binaries run in interleaved rounds:--layout --eval(round 1)--layout --eval(round 2)--layout --dump markdown(round 1)--layout --dump markdown(round 2)