[Prototype] Feature-gate heavy derives (MallocSizeOf, ToShmem, SpecifiedValueInfo, ToTyped) to improve compile times - #3
Draft
nicoburns wants to merge 1 commit into
Conversation
…edValueInfo, ToTyped)
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Prototype / experiment — makes the heavy trait derives in the
stylocrate optional via cargo features, to reduce compile times for embedders that don't need them. Defaults are unchanged: all features stay on by default (and are forced on bygecko), so existing consumers compile the exact same code.New features on the
stylocrate:malloc_size_ofderive(MallocSizeOf)expansions (~860 sites) + memory-reporting fnsto_shmemderive(ToShmem)expansions +selectors/to_shmem+ToShmemimplsspecified_value_infoderive(SpecifiedValueInfo)+ the per-propertySUPPORTED_TYPES/completion-keyword tables (supports_type,collect_property_completion_keywords)typed_omderive(ToTyped), thetyped_ommodule, and all reification codedefault = ["servo", "malloc_size_of", "to_shmem", "specified_value_info", "typed_om"]. To disable the gates:default-features = false, features = ["servo"].Mechanism
Rather than sprinkling
#[cfg_attr(feature = ..., derive(...))]over ~940 derive sites (huge diff, and awkward to keep in sync with upstream), this exploits the existing centralmod derivesre-export hub instyle/lib.rs: when a feature is off, the derive name is re-pointed at a no-op derive macro (added tostyle_derive) that accepts the same helper attributes (#[shmem(...)],#[value_info(...)],#[typed(...)],#[ignore_malloc_size_of]) but expands to nothing:This skips both the derive expansion and the type-checking of the expanded impls, which is where the compile time goes. The rest of the diff is
#[cfg(feature = ...)]on the handwritten trait impls, imports, and call sites that require the derived impls to exist (typed_om reification code,PropertyDeclarationBlock: ToShmem, the property value-info tables inproperties.mako.rs, memory-reporting entry points, etc.). The traits themselves remain defined unconditionally, so generic bounds still compile.Notes:
selectors/to_shmemmoved from theservofeature into the newto_shmemfeature.CalcNodeLeaf'sToTypedsupertrait is replaced by aCalcLeafToTypedalias that is literallyToTypedwhentyped_omis on, and a blanket-implemented empty trait when off.cfg_attr(..., allow(unused_imports, dead_code))(active only when any gate is off) keeps that config warning-free without churning hundreds of import lines. Default builds keep full warnings.MallocSizeOf— the no-op-derive approach avoided the per-site yak-shave.Compile-time measurements
2-core Linux VM, rustc 1.95.0, debug profile. "Gated off" =
-p stylo --no-default-features --features servo.cargo build(workspace)stylocrate unit (cargo--timings)cargo check(workspace)touch style/lib.rs && cargo checkDefault-feature times are identical to pre-change baseline (98 s / 42 s / 9 s), confirming default behavior is unchanged. The win is real but more modest than the derive counts might suggest — the remaining frontend time is dominated by the always-on derives (
ToCss,ToComputedValue,ToResolvedValue,Parse,Animate, ...) and general type-checking of the ~276k-line crate.Validation
cargo check(default features): cleancargo check -p stylo --no-default-features --features servo: clean (no warnings)cargo fmt --check: cleanThe
geckoconfiguration compiles the same code as before (it force-enables all four features) but wasn't buildable here (needs bindgen/mozbuild). Intermediate feature combinations (e.g.typed_omoff butspecified_value_infoon) haven't been exhaustively tested.Link to Devin session: https://app.devin.ai/sessions/e8fbaf225d8a40cea95584e606d17c72
Requested by: @nicoburns