Skip to content

Compile-time experiment: table-driven dispatch for giant per-property match statements - #2

Draft
nicoburns wants to merge 1 commit into
mainfrom
devin/1785851583-table-driven-dispatch
Draft

Compile-time experiment: table-driven dispatch for giant per-property match statements#2
nicoburns wants to merge 1 commit into
mainfrom
devin/1785851583-table-driven-dispatch

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

This is a compile-time experiment, not a functional change. It replaces the largest mako-generated per-property match statements with static arrays of function pointers indexed by property-id discriminant, to test the hypothesis that giant 200+-arm matches are what makes the stylo crate slow to compile.

Converted (largest generated matches by line count in the generated properties.rs):

  • AnimationValue::from_declaration (~10,300 generated lines, incl. the nested CSSWideKeyword match) → FROM_DECL / FROM_KEYWORD tables of per-property fns
  • ComputedValues::computed_or_resolved_declaration (~3,200 lines) → TO_DECL table
  • ComputedValues::computed_or_resolved_value (~2,800 lines) → TO_CSS table
  • impl Animate for AnimationValue (~2,700 lines) → ANIMATE table
  • ComputedValues::property_value_to_typed_value_list (~1,800 lines) → TO_TYPED table
  • AnimationValue::from_computed_values, AnimationValue::uncompute, AnimationValue::set_in_style_for_servo, AnimationValue::is_different_for, impl ComputeSquaredDistance for AnimationValue → corresponding tables

Each table is [fn(...); property_counts::LONGHANDS] with one generated function per (physical) longhand; non-applicable slots point at a shared None/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 servo feature, debug profile)

Metric Before After
Cold cargo build (workspace) 94 s 91 s
stylo unit time (cargo --timings) 50.8 s 51.6 s
touch style/lib.rs && cargo check (CARGO_INCREMENTAL=0, 3 runs) 19.0 / 19.4 / 19.7 s 19.7 / 19.7 / 19.8 s
Generated properties.rs lines 123,136 140,085

Result: 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 check passes with no new warnings.
  • cargo test --workspace --exclude stylo passes. (stylo's own lib tests fail to compile on main too — pre-existing PseudoElement::MozRubyText/FirstLine test breakage in style/selector_parser.rs, unrelated to this change.)

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

@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