-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Reduce amount of Mako-generated code in style #17703
Conversation
@bors-servo try https://treeherder.mozilla.org/#/jobs?repo=try&revision=2f6adcbd0a5dbfdc242f647921e7c13816f96506 Another factor that could explain some of the difference: |
Reduce amount of Mako-generated code in style In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as `LonghandId`. Fix https://bugzilla.mozilla.org/show_bug.cgi?id=1377262 Machine code size is measured with [bloaty](https://github.com/google/bloaty), looking at the total "VM size" in order to exclude debug info (which is stripped in binaries shipped to users). ``` mach build-geckolib --release bloaty target/geckolib/release/libgeckoservo.a ``` Initial size was 9.56Mi. Successive commits in this PR bring it to 9.55Mi, 9.51Mi, 9.44Mi, 9.31Mi, 8.89Mi, 8.89Mi, and 7.54Mi. Total savings: 2.02 MiB. In an optimized Firefox build with `mach build && mach package`, the size of `obj-x86_64-pc-linux-gnu/dist/firefox/libxul.so` goes from 109.11 MiB to 107.49 MiB, saving 1.62 MiB. I don’t really know how to explain the difference. Does `libgeckoservo.a` contain code that ends up not being used in `libxul.so`? <!-- 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/17703) <!-- Reviewable:end -->
There may be more of this still doable. Look for Mako |
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
Reduce amount of Mako-generated code in style In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as `LonghandId`. Fix https://bugzilla.mozilla.org/show_bug.cgi?id=1377262 Machine code size is measured with [bloaty](https://github.com/google/bloaty), looking at the total "VM size" in order to exclude debug info (which is stripped in binaries shipped to users). ``` mach build-geckolib --release bloaty target/geckolib/release/libgeckoservo.a ``` Initial size was 9.56Mi. Successive commits in this PR bring it to 9.55Mi, 9.51Mi, 9.44Mi, 9.31Mi, 8.89Mi, 8.89Mi, and 7.54Mi. Total savings: 2.02 MiB. In an optimized Firefox build with `mach build && mach package`, the size of `obj-x86_64-pc-linux-gnu/dist/firefox/libxul.so` goes from 109.11 MiB to 107.49 MiB, saving 1.62 MiB. I don’t really know how to explain the difference. Does `libgeckoservo.a` contain code that ends up not being used in `libxul.so`? <!-- 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/17703) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
Reduce amount of Mako-generated code in style In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as `LonghandId`. Fix https://bugzilla.mozilla.org/show_bug.cgi?id=1377262 Machine code size is measured with [bloaty](https://github.com/google/bloaty), looking at the total "VM size" in order to exclude debug info (which is stripped in binaries shipped to users). ``` mach build-geckolib --release bloaty target/geckolib/release/libgeckoservo.a ``` Initial size was 9.56Mi. Successive commits in this PR bring it to 9.55Mi, 9.51Mi, 9.44Mi, 9.31Mi, 8.89Mi, 8.89Mi, and 7.54Mi. Total savings: 2.02 MiB. In an optimized Firefox build with `mach build && mach package`, the size of `obj-x86_64-pc-linux-gnu/dist/firefox/libxul.so` goes from 109.11 MiB to 107.49 MiB, saving 1.62 MiB. I don’t really know how to explain the difference. Does `libgeckoservo.a` contain code that ends up not being used in `libxul.so`? <!-- 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/17703) <!-- Reviewable:end -->
Looks like buildbot just didn’t schedule some of the jobs. @bors-servo try |
Reduce amount of Mako-generated code in style In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as `LonghandId`. Fix https://bugzilla.mozilla.org/show_bug.cgi?id=1377262 Machine code size is measured with [bloaty](https://github.com/google/bloaty), looking at the total "VM size" in order to exclude debug info (which is stripped in binaries shipped to users). ``` mach build-geckolib --release bloaty target/geckolib/release/libgeckoservo.a ``` Initial size was 9.56Mi. Successive commits in this PR bring it to 9.55Mi, 9.51Mi, 9.44Mi, 9.31Mi, 8.89Mi, 8.89Mi, and 7.54Mi. Total savings: 2.02 MiB. In an optimized Firefox build with `mach build && mach package`, the size of `obj-x86_64-pc-linux-gnu/dist/firefox/libxul.so` goes from 109.11 MiB to 107.49 MiB, saving 1.62 MiB. I don’t really know how to explain the difference. Does `libgeckoservo.a` contain code that ends up not being used in `libxul.so`? <!-- 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/17703) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
… rather than generating similar code for each shorthand.
… rather than generating similar code for every longhand property.
… rather than generating similar code for each shorthand.
… rather than generating similar code for every longhand property
Tests are green, fixup commits are squashed, this is good to review and land. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Typo in the first commit message (s/genrated/generated
)
maybe_wm = ", wm" if property.logical else "" | ||
maybe_cacheable = ", cacheable" if property.has_uncacheable_values == "True" else "" | ||
props_need_device = "content list_style_type".split() if product == "gecko" else [] | ||
maybe_device = ", context.device" if property.ident in props_need_device else "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These hacks should go away eventually... sigh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend adding ?w=1
to github URLs to make diff not show as modified lines where only indentation changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know this is just moving code around... It's just that seeing this makes me sad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor comments. r=me
shorthands::${shorthand.ident}::parse_into(declarations, context, input) | ||
.map_err(|_| PropertyDeclarationParseError::InvalidValue("${shorthand.ident}".into())) | ||
.map_err(|_| PropertyDeclarationParseError::InvalidValue( | ||
"${shorthand.ident}".into() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I suspect this really wants do do shorthand.name
... But this is preexisting anyway.
} | ||
specified.map(|s| PropertyDeclaration::${property.camel_case}(s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think you can just remove the closure (specified.map(PropertyDeclaration::${property.camel_case})
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done so in a following commit.
if specified.is_err() { | ||
while let Ok(_) = input.next() {} // Look for var() after the error. | ||
} | ||
let var = input.seen_var_functions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't this just be:
if specified.is_err() {
while let Ok(_) = input.next() {} // Look for var() after the error.
if input.seen_var_functions() {
// ...
}
}
Seems easier to understand off-hand, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is rewritten in a following commit.
} | ||
}) | ||
}).map(|declaration| { | ||
declarations.push(declaration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't love to use map with side effects, but I guess it's not a big deal.
maybe_wm = ", wm" if property.logical else "" | ||
maybe_cacheable = ", cacheable" if property.has_uncacheable_values == "True" else "" | ||
props_need_device = "content list_style_type".split() if product == "gecko" else [] | ||
maybe_device = ", context.device" if property.ident in props_need_device else "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know this is just moving code around... It's just that seeing this makes me sad.
@@ -552,6 +462,11 @@ impl LonghandId { | |||
} | |||
} | |||
|
|||
fn inherited(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could try to use this more in a few places, I think it could reduce a bit of code size here and there too.
@@ -2838,16 +2821,18 @@ pub fn apply_declarations<'a, F, I>(device: &Device, | |||
CascadeLevel::UserNormal | | |||
CascadeLevel::UserImportant | | |||
CascadeLevel::UAImportant) { | |||
let non_transparent_background; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Use match
here?
let non_transparent_background = match *declaration {
PropertyDeclaration::BackgroundColor(ref color) => color.is_non_transparent(),
_ => continue,
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@bors-servo r=emilio |
📌 Commit 09d6c83 has been approved by |
Reduce amount of Mako-generated code in style In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as `LonghandId`. Fix https://bugzilla.mozilla.org/show_bug.cgi?id=1377262 Machine code size is measured with [bloaty](https://github.com/google/bloaty), looking at the total "VM size" in order to exclude debug info (which is stripped in binaries shipped to users). ``` mach build-geckolib --release bloaty target/geckolib/release/libgeckoservo.a ``` Initial size was 9.56Mi. Successive commits in this PR bring it to 9.55Mi, 9.51Mi, 9.44Mi, 9.31Mi, 8.89Mi, 8.89Mi, and 7.54Mi. Total savings: 2.02 MiB. In an optimized Firefox build with `mach build && mach package`, the size of `obj-x86_64-pc-linux-gnu/dist/firefox/libxul.so` goes from 109.11 MiB to 107.49 MiB, saving 1.62 MiB. I don’t really know how to explain the difference. Does `libgeckoservo.a` contain code that ends up not being used in `libxul.so`? <!-- 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/17703) <!-- Reviewable:end -->
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as
LonghandId
.Fix https://bugzilla.mozilla.org/show_bug.cgi?id=1377262
Machine code size is measured with bloaty, looking at the total "VM size" in order to exclude debug info (which is stripped in binaries shipped to users).
Initial size was 9.56Mi. Successive commits in this PR bring it to 9.55Mi, 9.51Mi, 9.44Mi, 9.31Mi, 8.89Mi, 8.89Mi, and 7.54Mi. Total savings: 2.02 MiB.
In an optimized Firefox build with
mach build && mach package
, the size ofobj-x86_64-pc-linux-gnu/dist/firefox/libxul.so
goes from 109.11 MiB to 107.49 MiB, saving 1.62 MiB. I don’t really know how to explain the difference. Doeslibgeckoservo.a
contain code that ends up not being used inlibxul.so
?This change is