Skip to content

Commit a9f0e29

Browse files
committed
servo: Merge #15992 - Rewrite PropertyDeclaration::id to help the optimizer (from servo:id-table); r=bholley
If I’m reading the release-mode assembly correctly, before this change `PropertyDeclaration::id` is implemented with a computed jump: ```assembly lea rcx, [rip + .LJTI117_0] movsxd rax, dword ptr [rcx + 4*rax] add rax, rcx jmp rax .LBB117_3: mov dword ptr [rdi], 65536 mov rax, rdi ret .LBB117_2: mov dword ptr [rdi], 0 mov rax, rdi ret .LBB117_4: mov dword ptr [rdi], 131072 mov rax, rdi ret .LBB117_6: mov dword ptr [rdi], 262144 mov rax, rdi ret .LBB117_7: mov dword ptr [rdi], 327680 mov rax, rdi ret ; Four similar lines repeated for each of the few hundred variants... ``` With Rust 1.15 (currently used for geckolib) this doesn’t change significantly. In Nightly 1.17 however, the compiled code uses a lookup table, possibly thanks to rust-lang/rust#39456. ```assembly movq (%rsi), %rax cmpq $171, %rax jne .LBB23_1 addq $8, %rsi movq %rsi, 8(%rdi) movb $1, %al jmp .LBB23_3 .LBB23_1: xorq $128, %rax leaq .Lswitch.table.6(%rip), %rcx movb (%rax,%rcx), %al movb %al, 1(%rdi) xorl %eax, %eax .LBB23_3: movb %al, (%rdi) movq %rdi, %rax retq ``` Source-Repo: https://github.com/servo/servo Source-Revision: 9e8e1a47241c6906b4f5777da0d04e3655982fae --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 80fb6158601e5f4715805013dd7c9492ceb38461
1 parent b769db9 commit a9f0e29

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

servo/components/style/properties/properties.mako.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -1094,17 +1094,32 @@ impl PropertyDeclaration {
10941094
/// Given a property declaration, return the property declaration id.
10951095
pub fn id(&self) -> PropertyDeclarationId {
10961096
match *self {
1097+
PropertyDeclaration::Custom(ref name, _) => {
1098+
return PropertyDeclarationId::Custom(name)
1099+
}
1100+
PropertyDeclaration::CSSWideKeyword(id, _) |
1101+
PropertyDeclaration::WithVariables(id, _) => {
1102+
return PropertyDeclarationId::Longhand(id)
1103+
}
1104+
_ => {}
1105+
}
1106+
let longhand_id = match *self {
10971107
% for property in data.longhands:
10981108
PropertyDeclaration::${property.camel_case}(..) => {
1099-
PropertyDeclarationId::Longhand(LonghandId::${property.camel_case})
1109+
LonghandId::${property.camel_case}
11001110
}
11011111
% endfor
1102-
PropertyDeclaration::CSSWideKeyword(id, _) => PropertyDeclarationId::Longhand(id),
1103-
PropertyDeclaration::WithVariables(id, _) => PropertyDeclarationId::Longhand(id),
1104-
PropertyDeclaration::Custom(ref name, _) => {
1105-
PropertyDeclarationId::Custom(name)
1112+
PropertyDeclaration::CSSWideKeyword(..) |
1113+
PropertyDeclaration::WithVariables(..) |
1114+
PropertyDeclaration::Custom(..) => {
1115+
debug_assert!(false, "unreachable");
1116+
// This value is never used, but having an expression of the same "shape"
1117+
// as for other variants helps the optimizer compile this `match` expression
1118+
// to a lookup table.
1119+
LonghandId::BackgroundColor
11061120
}
1107-
}
1121+
};
1122+
PropertyDeclarationId::Longhand(longhand_id)
11081123
}
11091124

11101125
fn with_variables_from_shorthand(&self, shorthand: ShorthandId) -> Option< &str> {

0 commit comments

Comments
 (0)