Compile-time experiment: table-driven dispatch for giant per-property match statements - #2
Draft
nicoburns wants to merge 1 commit into
Draft
Compile-time experiment: table-driven dispatch for giant per-property match statements#2nicoburns wants to merge 1 commit into
nicoburns wants to merge 1 commit into
Conversation
🤖 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
This is a compile-time experiment, not a functional change. It replaces the largest mako-generated per-property
matchstatements with static arrays of function pointers indexed by property-id discriminant, to test the hypothesis that giant 200+-arm matches are what makes thestylocrate slow to compile.Converted (largest generated matches by line count in the generated
properties.rs):AnimationValue::from_declaration(~10,300 generated lines, incl. the nestedCSSWideKeywordmatch) →FROM_DECL/FROM_KEYWORDtables of per-propertyfnsComputedValues::computed_or_resolved_declaration(~3,200 lines) →TO_DECLtableComputedValues::computed_or_resolved_value(~2,800 lines) →TO_CSStableimpl Animate for AnimationValue(~2,700 lines) →ANIMATEtableComputedValues::property_value_to_typed_value_list(~1,800 lines) →TO_TYPEDtableAnimationValue::from_computed_values,AnimationValue::uncompute,AnimationValue::set_in_style_for_servo,AnimationValue::is_different_for,impl ComputeSquaredDistance for AnimationValue→ corresponding tablesEach table is
[fn(...); property_counts::LONGHANDS]with one generated function per (physical) longhand; non-applicable slots point at a sharedNone/unreachable stub. Dispatch reads the enum tag (same repr tricks the existing code already uses) and indexes the table. Behavior and public API are unchanged.Measurements (2-core machine, rustc 1.95.0, default
servofeature, debug profile)cargo build(workspace)stylounit time (cargo--timings)touch style/lib.rs && cargo check(CARGO_INCREMENTAL=0, 3 runs)properties.rslinesResult: neutral. On this toolchain, converting these matches to table-driven dispatch does not measurably improve compile times (differences are within run-to-run noise; the generated file actually grows ~17k lines from the per-property functions). The giant matches do not appear to be the frontend bottleneck for this crate on rustc 1.95.
Verification
cargo checkpasses with no new warnings.cargo test --workspace --exclude stylopasses. (stylo's own lib tests fail to compile onmaintoo — pre-existingPseudoElement::MozRubyText/FirstLinetest breakage instyle/selector_parser.rs, unrelated to this change.)Link to Devin session: https://app.devin.ai/sessions/c1053e755c5f431990f0fd9ec986740c
Requested by: @nicoburns