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

Reduce amount of Mako-generated code in style #17703

Merged
merged 10 commits into from
Jul 13, 2017
Merged

Reduce amount of Mako-generated code in style #17703

merged 10 commits into from
Jul 13, 2017

Conversation

SimonSapin
Copy link
Member

@SimonSapin SimonSapin commented Jul 12, 2017

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).

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?


This change is Reviewable

@SimonSapin
Copy link
Member Author

@bors-servo try

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


Another factor that could explain some of the difference: mach build-geckolib uses Rust 1.17.0 (which it downloads itself), whereas Firefox uses the system’s Rust which on my build machine is 1.18.0. The latter adds field re-ordering. If that or other new optimizations reduce the size of all Rust code, the saving would be roughly proportionally reduced.

@bors-servo
Copy link
Contributor

⌛ Trying commit 1d2f11b with merge 322c3a4...

bors-servo pushed a commit that referenced this pull request Jul 12, 2017
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 -->
@SimonSapin
Copy link
Member Author

In multiple places, instead of generated similar code for each CSS property, have a single code path that uses an enum such as LonghandId.

There may be more of this still doable. Look for Mako % for loops that generate code for each CSS property in *.mako.rs files.

@bors-servo
Copy link
Contributor

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 13, 2017
@SimonSapin
Copy link
Member Author

@bors-servo
Copy link
Contributor

⌛ Trying commit a234f53 with merge 395b5ba...

bors-servo pushed a commit that referenced this pull request Jul 13, 2017
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 -->
@bors-servo
Copy link
Contributor

@SimonSapin
Copy link
Member Author

@bors-servo
Copy link
Contributor

⌛ Trying commit 5922bc0 with merge 9b14022...

bors-servo pushed a commit that referenced this pull request Jul 13, 2017
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 -->
@SimonSapin
Copy link
Member Author

Looks like buildbot just didn’t schedule some of the jobs.

@bors-servo try

@bors-servo
Copy link
Contributor

⌛ Trying commit db6cdf4 with merge 778582c...

bors-servo pushed a commit that referenced this pull request Jul 13, 2017
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 -->
@bors-servo
Copy link
Contributor

@SimonSapin
Copy link
Member Author

Tests are green, fixup commits are squashed, this is good to review and land.

Copy link
Member

@emilio emilio left a 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 ""
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

@emilio emilio left a 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()
Copy link
Member

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))
Copy link
Member

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}))

Copy link
Member Author

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();
Copy link
Member

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?

Copy link
Member Author

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)
Copy link
Member

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 ""
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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,
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@SimonSapin
Copy link
Member Author

@bors-servo r=emilio

@bors-servo
Copy link
Contributor

📌 Commit 09d6c83 has been approved by emilio

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 13, 2017
bors-servo pushed a commit that referenced this pull request Jul 13, 2017
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 -->
@bors-servo
Copy link
Contributor

⌛ Testing commit 09d6c83 with merge 68ae7ce...

@bors-servo
Copy link
Contributor

☀️ 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
Approved by: emilio
Pushing 68ae7ce to master...

@bors-servo bors-servo merged commit 09d6c83 into master Jul 13, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 13, 2017
@SimonSapin SimonSapin deleted the code-size branch July 13, 2017 19:07
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.

4 participants