Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate some PropertyDeclaration methods by hand 🐉🐲 #19956

Merged
merged 9 commits into from Feb 6, 2018

Conversation

@nox
Copy link
Member

nox commented Feb 5, 2018

We rely on rust-lang/rfcs#2195 to make some enums share the same discriminants by definition.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1428285.

This change is Reviewable

nox added 2 commits Feb 4, 2018
This will help us reuse code between different variants in a later patch,
to implement Clone by hand to optimise it.
@highfive
Copy link

highfive commented Feb 5, 2018

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/data.py, components/style/properties/helpers.mako.rs, components/style/properties/declaration_block.rs, components/style/properties/helpers/animated_properties.mako.rs, components/style/properties/properties.mako.rs
  • @canaltinova: components/style/properties/data.py, components/style/properties/helpers.mako.rs, components/style/properties/declaration_block.rs, components/style/properties/helpers/animated_properties.mako.rs, components/style/properties/properties.mako.rs
  • @emilio: components/style/properties/data.py, components/style/properties/helpers.mako.rs, components/style/properties/declaration_block.rs, components/style/properties/helpers/animated_properties.mako.rs, components/style/properties/properties.mako.rs
@highfive
Copy link

highfive commented Feb 5, 2018

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
/// Servo's representation for a property declaration.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, PartialEq)]
#[derive(PartialEq)]
#[repr(u8)]

This comment has been minimized.

@SimonSapin

SimonSapin Feb 5, 2018

Member

Doesn’t this have more than 256 variants?

This comment has been minimized.

@nox

nox Feb 5, 2018

Author Member

Yes. :D Just realised with the geckotry failing to build.

@nox nox force-pushed the derive-all-the-things branch from 9362314 to 2d59b50 Feb 5, 2018
@nox
Copy link
Member Author

nox commented Feb 5, 2018

@nox nox force-pushed the derive-all-the-things branch 4 times, most recently from 516acf6 to eec63ec Feb 5, 2018
@nox nox changed the title Implement Clone for PropertyDeclaration by hand 🐉🐲 (Do not merge) Implement Clone for PropertyDeclaration by hand 🐉🐲 Feb 5, 2018
@nox
Copy link
Member Author

nox commented Feb 5, 2018

[nox:~/src/gecko] 2s 130
⌀ size XUL.old
__TEXT	__DATA	__OBJC	others	dec	hex
88387584	5271552	0	65503232	159162368	97ca000

[nox:~/src/gecko]
⌀ ../bloaty/build/bloaty -d symbols -n 100000000 XUL.old | grep -w PropertyDeclaration
   0.0%  45.1Ki style::properties::PropertyDeclaration::to_css::h70aa9127e631f236                 45.1Ki   0.0%
   0.0%  32.8Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialEq$GT$:  32.8Ki   0.0%
   0.0%  32.6Ki __ZN79_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialE  32.6Ki   0.0%
   0.0%  29.7Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  29.7Ki   0.0%
   0.0%  29.3Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  29.3Ki   0.0%
   0.0%  27.9Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  27.9Ki   0.0%
   0.0%  27.6Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$GT$::c  27.6Ki   0.0%
   0.0%  15.7Ki __ZN87_$LT$style..properties..PropertyDeclaration$u20$as$u20$malloc_size_of..Mal  15.7Ki   0.0%
   0.0%  9.78Ki style::properties::PropertyDeclaration::parse_into::h35ee1deaf54c46b6             9.78Ki   0.0%
   0.0%  4.17Ki style::properties::PropertyDeclaration::id::h9f691ba9ad1fcbbc                     4.17Ki   0.0%
   0.0%     320 style::properties::PropertyDeclaration::get_system::h4a3d3afe5a217d86                320   0.0%
   0.0%      32 style::properties::PropertyDeclaration::get_css_wide_keyword::he3ca52066fa1abf7       32   0.0%

[nox:~/src/gecko] 2s
⌀ size XUL.new
__TEXT	__DATA	__OBJC	others	dec	hex
88190976	5271552	0	65482752	158945280	9795000

[nox:~/src/gecko]
⌀ ../bloaty/build/bloaty -d symbols -n 100000000 XUL.new | grep -w PropertyDeclaration
   0.0%  45.2Ki style::properties::PropertyDeclaration::to_css::hc9cb9df128aea03f                 45.2Ki   0.0%
   0.0%  22.8Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialEq$GT$:  22.8Ki   0.0%
   0.0%  22.3Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$GT$::c  22.3Ki   0.0%
   0.0%  15.6Ki __ZN87_$LT$style..properties..PropertyDeclaration$u20$as$u20$malloc_size_of..Mal  15.6Ki   0.0%
   0.0%  9.89Ki style::properties::PropertyDeclaration::parse_into::ha8f87489fe4f89f8             9.89Ki   0.0%
   0.0%     320 style::properties::PropertyDeclaration::get_system::h07f9efc836477132                320   0.0%
   0.0%      96 style::properties::PropertyDeclaration::id::hd928f19c20f0e1bc                         96   0.0%
   0.0%      32 style::properties::PropertyDeclaration::get_css_wide_keyword::hfd74e2964361369d       32   0.0%

It looks good but I'm not sure I should trust those results.

Cc @bholley @emilio

Also, I've yet to make a geckotry with the latest commits I added.

https://treeherder.mozilla.org/#/jobs?repo=try&revision=d0b009ecd44b0a7327c507b37a9b188e2a5b7e7b

@nox nox changed the title (Do not merge) Implement Clone for PropertyDeclaration by hand 🐉🐲 (Do not merge) Generate some PropertyDeclaration methods 🐉🐲 Feb 5, 2018
@nox nox force-pushed the derive-all-the-things branch from eec63ec to 2bdc118 Feb 5, 2018
@nox
Copy link
Member Author

nox commented Feb 5, 2018

Silly me had not put #[inline] on the Clone and PartialEq methods, that explains why there was only one Clone in XUL.new:

⌀ ../bloaty/build/bloaty -d symbols -n 1000000000 XUL.new | grep -w PropertyDeclaration
   0.0%  45.2Ki style::properties::PropertyDeclaration::to_css::hc9cb9df128aea03f                 45.2Ki   0.0%
   0.0%  23.0Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialEq$GT$:  23.0Ki   0.0%
   0.0%  22.7Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  22.7Ki   0.0%
   0.0%  22.7Ki __ZN79_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialE  22.7Ki   0.0%
   0.0%  22.3Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  22.3Ki   0.0%
   0.0%  22.2Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  22.2Ki   0.0%
   0.0%  21.8Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$GT$::c  21.8Ki   0.0%
   0.0%  15.6Ki __ZN87_$LT$style..properties..PropertyDeclaration$u20$as$u20$malloc_size_of..Mal  15.6Ki   0.0%
   0.0%  9.89Ki style::properties::PropertyDeclaration::parse_into::ha8f87489fe4f89f8             9.89Ki   0.0%
   0.0%     320 style::properties::PropertyDeclaration::get_system::h07f9efc836477132                320   0.0%
   0.0%      96 style::properties::PropertyDeclaration::id::hd928f19c20f0e1bc                         96   0.0%
   0.0%      32 style::properties::PropertyDeclaration::get_css_wide_keyword::hfd74e2964361369d       32   0.0%
@nox
Copy link
Member Author

nox commented Feb 5, 2018

Everything is orange. Will investigate tomorrow. Probably some dumb error somewhere.

@nox nox force-pushed the derive-all-the-things branch 2 times, most recently from d4f22cb to 27fa1a7 Feb 5, 2018
@nox
Copy link
Member Author

nox commented Feb 6, 2018

Latest results with bloaty, and the missing #[inline] on clone and eq:

[nox:~/src/gecko]
⌀ size XUL.old
__TEXT	__DATA	__OBJC	others	dec	hex
88387584	5271552	0	65503232	159162368	97ca000

[nox:~/src/gecko]
⌀ ../bloaty/build/bloaty -d symbols -n 1000000000 XUL.old | grep -w PropertyDeclaration
   0.0%  45.1Ki style::properties::PropertyDeclaration::to_css::h70aa9127e631f236                 45.1Ki   0.0%
   0.0%  32.8Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialEq$GT$:  32.8Ki   0.0%
   0.0%  32.6Ki __ZN79_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialE  32.6Ki   0.0%
   0.0%  29.7Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  29.7Ki   0.0%
   0.0%  29.3Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  29.3Ki   0.0%
   0.0%  27.9Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  27.9Ki   0.0%
   0.0%  27.6Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$GT$::c  27.6Ki   0.0%
   0.0%  15.7Ki __ZN87_$LT$style..properties..PropertyDeclaration$u20$as$u20$malloc_size_of..Mal  15.7Ki   0.0%
   0.0%  9.78Ki style::properties::PropertyDeclaration::parse_into::h35ee1deaf54c46b6             9.78Ki   0.0%
   0.0%  4.17Ki style::properties::PropertyDeclaration::id::h9f691ba9ad1fcbbc                     4.17Ki   0.0%
   0.0%     320 style::properties::PropertyDeclaration::get_system::h4a3d3afe5a217d86                320   0.0%
   0.0%      32 style::properties::PropertyDeclaration::get_css_wide_keyword::he3ca52066fa1abf7       32   0.0%

[nox:~/src/gecko] 3s
⌀ size XUL.new
__TEXT	__DATA	__OBJC	others	dec	hex
88317952	5271552	0	65495040	159084544	97b7000

[nox:~/src/gecko]
⌀ ../bloaty/build/bloaty -d symbols -n 1000000000 XUL.new | grep -w PropertyDeclaration
   0.0%  45.2Ki style::properties::PropertyDeclaration::to_css::he42a36e94b3deab2                 45.2Ki   0.0%
   0.0%  23.0Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialEq$GT$:  23.0Ki   0.0%
   0.0%  22.7Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  22.7Ki   0.0%
   0.0%  22.7Ki __ZN79_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..cmp..PartialE  22.7Ki   0.0%
   0.0%  22.3Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  22.3Ki   0.0%
   0.0%  22.2Ki __ZN77_$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$  22.2Ki   0.0%
   0.0%  21.8Ki _$LT$style..properties..PropertyDeclaration$u20$as$u20$core..clone..Clone$GT$::c  21.8Ki   0.0%
   0.0%  15.6Ki __ZN87_$LT$style..properties..PropertyDeclaration$u20$as$u20$malloc_size_of..Mal  15.6Ki   0.0%
   0.0%  9.89Ki style::properties::PropertyDeclaration::parse_into::ha8f87489fe4f89f8             9.89Ki   0.0%
   0.0%     320 style::properties::PropertyDeclaration::get_system::h07f9efc836477132                320   0.0%
   0.0%      96 style::properties::PropertyDeclaration::id::hd928f19c20f0e1bc                         96   0.0%
   0.0%      32 style::properties::PropertyDeclaration::get_css_wide_keyword::hfd74e2964361369d       32   0.0%

Geckotry seems green: https://treeherder.mozilla.org/#/jobs?repo=try&revision=2cb22ae5e6be97fcc968dc965827234d54f26b47&selectedJob=160528329

@nox nox changed the title (Do not merge) Generate some PropertyDeclaration methods 🐉🐲 Generate some PropertyDeclaration methods 🐉🐲 Feb 6, 2018
@nox nox changed the title Generate some PropertyDeclaration methods 🐉🐲 Generate some PropertyDeclaration methods by hand 🐉🐲 Feb 6, 2018
@emilio
emilio approved these changes Feb 6, 2018
Copy link
Member

emilio left a comment

r=me, with the comments and a different name for is_size_type (feel free to rename it on a followup commit if it's easier).

@@ -903,6 +903,7 @@
<%call expr="longhand(name,
predefined_type=length_type,
logical=logical,
is_size_type=True,

This comment has been minimized.

@emilio

emilio Feb 6, 2018

Member

Let's rename this to something that screams out more, like is_gecko_size_type_hack or something.

%>
/// ${property.name}
${property.camel_case}(${ty}),
variants.append({

This comment has been minimized.

@emilio

emilio Feb 6, 2018

Member

Can you document why do we need this complexity here, please?

};
PropertyDeclarationId::Longhand(longhand_id)
PropertyDeclarationId::Longhand(
unsafe { *(self as *const _ as *const LonghandId) },

This comment has been minimized.

@emilio

emilio Feb 6, 2018

Member

Can we debug-assert this somehow at least, to ensure nobody messes up? I guess if they mess up it'd be completely orange but...

Also, please add a comment about why this is ok here so people don't scream :).

match self.value.from_shorthand {
// Normally, we shouldn't be printing variables here if they came from
// shorthands. But we should allow properties that came from shorthand
// aliases. That also matches with the Gecko behavior.

This comment has been minimized.

@emilio

emilio Feb 6, 2018

Member

Can you mention here that this is just a hack for -moz-transform, which is really a shorthand for who knows what reason?

Also we should try to unship that, so feel free to also add a FIXME(emilio) over there so I eventually do it.

${" | ".join("{}(ref this)".format(v) for v in variants)} => {
let other_repr =
&*(other as *const _ as *const PropertyDeclarationVariantRepr<${ty}>);
*this == other_repr.value

This comment has been minimized.

@emilio

emilio Feb 6, 2018

Member

Wonderfully evil :(

@@ -267,7 +268,6 @@ pub mod animated_properties {
%>

/// Servo's representation for a property declaration.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[repr(u16)]
pub enum PropertyDeclaration {

This comment has been minimized.

@emilio

emilio Feb 6, 2018

Member

Can you add a general overview of why don't we derive stuff here and similar?

@emilio
Copy link
Member

emilio commented Feb 6, 2018

If @SimonSapin sanity-checked this too it'd be nice, since he had concerns about doing the same kind of optimization in https://bugzilla.mozilla.org/show_bug.cgi?id=1428285#c2, it seems.

@nox nox force-pushed the derive-all-the-things branch from 4140a43 to 2ebdf21 Feb 6, 2018
nox added 2 commits Feb 5, 2018
This makes the enum `#[repr(u16)]` and generate code that shares the same
Clone::clone call for all variants sharing the same field type.
@nox
Copy link
Member Author

nox commented Feb 6, 2018

I added a comment in the commit message.

@bors-servo r=emilio,SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Feb 6, 2018

📌 Commit fd31712 has been approved by emilio,SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Feb 6, 2018

Testing commit fd31712 with merge 5304e8f...

bors-servo added a commit that referenced this pull request Feb 6, 2018
Generate some PropertyDeclaration methods by hand 🐉🐲

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19956)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 6, 2018

💔 Test failed - linux-rel-wpt

nox added 4 commits Feb 5, 2018
This relies on the fact that `#[repr(u16)]` on enums ensure the discriminant will
be the very first field of the enum value. This has always been the case, but it
has been formally defined only since rust-lang/rfcs#2195.

https://bugzilla.mozilla.org/show_bug.cgi?id=1428285
We first check that the discriminants are equal, then we pattern match only
on `*self` and use `PropertyDeclarationVariantRepr` to look into `other` directly.
We merge arms with identical field types.
@nox nox force-pushed the derive-all-the-things branch from fd31712 to 1f0a126 Feb 6, 2018
@nox
Copy link
Member Author

nox commented Feb 6, 2018

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

bors-servo commented Feb 6, 2018

📌 Commit 1f0a126 has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Feb 6, 2018

Testing commit 1f0a126 with merge 9faf0cd...

bors-servo added a commit that referenced this pull request Feb 6, 2018
Generate some PropertyDeclaration methods by hand 🐉🐲

We rely on rust-lang/rfcs#2195 to make some enums share the same discriminants by definition.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1428285.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19956)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 6, 2018

@bors-servo bors-servo merged commit 1f0a126 into master Feb 6, 2018
4 of 5 checks passed
4 of 5 checks passed
Taskcluster (pull_request) TaskGroup: failure
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
dependency-ci Dependencies checked
Details
homu Test successful
Details
@nox nox deleted the derive-all-the-things branch Feb 6, 2018
@ionutgoldan
Copy link

ionutgoldan commented Feb 13, 2018

These changes landed some fine performance improvements! Thank you!

== Change summary for alert #11504 (as of Tue, 06 Feb 2018 12:06:36 GMT) ==

Improvements:

5% Stylo Servo_DeclarationBlock_SetPropertyById_WithInitialSpace_Bench osx-10-10 opt 549,031.92 -> 519,840.33
2% Stylo Servo_DeclarationBlock_GetPropertyById_Bench windows7-32 opt 231,626.04 -> 226,308.08

For up to date results, see: https://treeherder.mozilla.org/perf.html#/alerts?id=11504

@bholley
Copy link
Contributor

bholley commented Feb 13, 2018

There are some more wins in #19966 that might also be attributable to this.

Awesome job @nox!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.