Skip to content

[compile-time experiment] Dedupe repeated per-longhand code in generated properties.rs - #4

Draft
nicoburns wants to merge 1 commit into
mainfrom
devin/1785851986-dedupe-generated-properties
Draft

[compile-time experiment] Dedupe repeated per-longhand code in generated properties.rs#4
nicoburns wants to merge 1 commit into
mainfrom
devin/1785851986-dedupe-generated-properties

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

Compile-time experiment: shrink the mako-generated properties.rs by factoring code that was emitted once per longhand into shared handwritten helpers, and measure the effect on build times.

What was deduplicated (all in helpers.mako.rs's longhand()/shorthand() defs):

  • Cascade glue: the ~40-line per-property CSSWideKeyword match in each cascade_property is replaced by one call to a new shared PropertyDeclaration::cascade_simple_wide_keyword(context, id, is_inherited, inherit_or_reset, reinherit_with_zoom) in style/properties/mod.rs. Per-property behavior (inherit vs reset, zoom-dependent re-inheritance, debug asserts, for_non_inherited_property) is passed via fn pointers/flags. Zoom-dependent longhands emit a tiny local reinherit_with_zoom fn.
  • Import boilerplate: the ~16 use lines per longhand module (and ~8 per shorthand module) become a single glob import of new longhand_prelude/shorthand_prelude modules.
  • Vector-list machinery: the per-property generic OwnedList<T> struct + Animate/ComputeSquaredDistance/ToAnimatedZero/From impls emitted for each vector longhand are replaced by three shared generic types in new style/properties/longhand_lists.rs (NonEmptyCommaList, EmptyCommaList, EmptySpaceList), chosen per property in the template. The shared-ArcSlice ComputedList path (only text-shadow in servo) stays templated.
  • from_gecko_keyword (already #[cfg(feature = "gecko")]) is now only emitted for gecko-engine builds.

Note: the shared list types now carry Animate/ToAnimatedZero blanket impls for any T meeting the bounds, whereas previously those impls only existed for longhands with a vector animation_type. This is a strict superset (no existing behavior changes).

Measurements

2-core linux VM, default (servo) features, protocol: cold rm -rf target && cargo build --timings; cargo check warm, then touch style/lib.rs && time cargo check (both with incremental on and with CARGO_INCREMENTAL=0).

Metric Before After
Generated properties.rs lines 123,136 109,723 (−10.9%)
Cold cargo build (total) 99.0s 97.9s
stylo unit time (cargo-timings) 53.4s 54.6s
touch style/lib.rs + cargo check (incremental) 8.3s 8.3s
same, CARGO_INCREMENTAL=0 20.4–20.9s 20.6–23.1s

Conclusion: the generated file shrinks by ~11%, but compile times are unchanged within noise. The deduplicated code was cheap-to-compile boilerplate; stylo's compile time appears dominated by the remaining giant match-based dispatch (PropertyDeclaration/AnimationValue/LonghandId impls), derives, and the per-field style-struct accessors, which are out of scope here (table-driven dispatch is being explored separately).

Testing

  • cargo check: clean, no new warnings.
  • cargo test --workspace --exclude stylo: all pass.
  • cargo test -p stylo fails to compile on main as well (pre-existing PseudoElement::MozRubyText/FirstLine errors in selector_parser.rs tests), unchanged by this PR.

Link to Devin session: https://app.devin.ai/sessions/4acc993f357a4cd9ac8e17704aa71ed6
Requested by: @nicoburns

…red helpers

Compile-time experiment: deduplicate the per-property cascade glue,
import boilerplate, and vector-longhand list machinery emitted by the
mako templates into shared handwritten helpers.
@nicoburns nicoburns self-assigned this Aug 4, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant