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

Make PropertyDeclaration tinier #15061

Closed
Manishearth opened this issue Jan 17, 2017 · 5 comments
Closed

Make PropertyDeclaration tinier #15061

Manishearth opened this issue Jan 17, 2017 · 5 comments
Labels
A-content/css Interacting with CSS from web content (parsing, serializing, introspection) C-is-this-done It is unclear if the issue has been resolved I-perf-bloat Unnecessary memory usage.

Comments

@Manishearth
Copy link
Member

Manishearth commented Jan 17, 2017

We should be doing more boxing here. It's more than a thousand bytes of inline space (mem::size_of) right now.

Properties larger than 10 bytes in Servo:

492 / clip
368 / transform-origin
248 / perspective-origin
248 / border-top-right-radius
248 / border-top-left-radius
248 / border-bottom-right-radius
248 / border-bottom-left-radius
240 / border-spacing
128 / word-spacing
128 / vertical-align
128 / line-height
124 / width
124 / top
124 / text-indent
124 / right
124 / perspective
124 / padding-top
124 / padding-right
124 / padding-left
124 / padding-inline-start
124 / padding-inline-end
124 / padding-bottom
124 / padding-block-start
124 / padding-block-end
124 / offset-inline-start
124 / offset-inline-end
124 / offset-block-start
124 / offset-block-end
124 / min-width
124 / min-inline-size
124 / min-height
124 / min-block-size
124 / max-width
124 / max-inline-size
124 / max-height
124 / max-block-size
124 / margin-top
124 / margin-right
124 / margin-left
124 / margin-inline-start
124 / margin-inline-end
124 / margin-bottom
124 / margin-block-start
124 / margin-block-end
124 / letter-spacing
124 / left
124 / inline-size
124 / height
124 / font-size
124 / flex-basis
124 / column-width
124 / column-gap
124 / bottom
124 / border-top-width
124 / border-right-width
124 / border-left-width
124 / border-inline-start-width
124 / border-inline-end-width
124 / border-bottom-width
124 / border-block-start-width
124 / border-block-end-width
124 / block-size
120 / outline-width
120 / outline-offset
72 / text-overflow
60 / -servo-text-decorations-in-effect
48 / outline-color
48 / border-top-color
48 / border-right-color
48 / border-left-color
48 / border-inline-start-color
48 / border-inline-end-color
48 / border-bottom-color
48 / border-block-start-color
48 / border-block-end-color
48 / background-color
40 / color
32 / content
24 / transition-timing-function
24 / transition-property
24 / transition-duration
24 / transition-delay
24 / transform
24 / text-shadow
24 / quotes
24 / list-style-image
24 / font-family
24 / filter
24 / counter-reset
24 / counter-increment
24 / box-shadow
24 / background-size
24 / background-repeat
24 / background-position-y
24 / background-position-x
24 / background-origin
24 / background-image
24 / background-clip
24 / background-attachment
24 / animation-timing-function
24 / animation-play-state
24 / animation-name
24 / animation-iteration-count
24 / animation-fill-mode
24 / animation-duration
24 / animation-direction
24 / animation-delay


Properties larger than 10 bytes in Stylo:
1512 / clip-path
568 / border-image-source
368 / transform-origin
248 / perspective-origin
248 / border-top-right-radius
248 / border-top-left-radius
248 / border-bottom-right-radius
248 / border-bottom-left-radius
248 / -moz-outline-radius-topright
248 / -moz-outline-radius-topleft
248 / -moz-outline-radius-bottomright
248 / -moz-outline-radius-bottomleft
240 / border-spacing
128 / word-spacing
128 / vertical-align
128 / scroll-snap-points-y
128 / scroll-snap-points-x
128 / line-height
124 / width
124 / top
124 / text-indent
124 / right
124 / perspective
124 / padding-top
124 / padding-right
124 / padding-left
124 / padding-inline-start
124 / padding-inline-end
124 / padding-bottom
124 / padding-block-start
124 / padding-block-end
124 / offset-inline-start
124 / offset-inline-end
124 / offset-block-start
124 / offset-block-end
124 / min-width
124 / min-inline-size
124 / min-height
124 / min-block-size
124 / max-width
124 / max-inline-size
124 / max-height
124 / max-block-size
124 / margin-top
124 / margin-right
124 / margin-left
124 / margin-inline-start
124 / margin-inline-end
124 / margin-bottom
124 / margin-block-start
124 / margin-block-end
124 / letter-spacing
124 / left
124 / inline-size
124 / height
124 / font-size
124 / flex-basis
124 / column-width
124 / column-rule-width
124 / column-gap
124 / bottom
124 / border-top-width
124 / border-right-width
124 / border-left-width
124 / border-inline-start-width
124 / border-inline-end-width
124 / border-bottom-width
124 / border-block-start-width
124 / border-block-end-width
124 / block-size
124 / -webkit-text-stroke-width
120 / outline-width
72 / text-overflow
48 / text-emphasis-color
48 / text-decoration-color
48 / stop-color
48 / outline-color
48 / list-style-image
48 / lighting-color
48 / flood-color
48 / column-rule-color
48 / border-top-color
48 / border-right-color
48 / border-left-color
48 / border-inline-start-color
48 / border-inline-end-color
48 / border-bottom-color
48 / border-block-start-color
48 / border-block-end-color
48 / background-color
48 / -webkit-text-stroke-color
48 / -webkit-text-fill-color
48 / -moz-binding
40 / grid-row-start
40 / grid-row-end
40 / grid-column-start
40 / grid-column-end
40 / color
32 / text-emphasis-style
32 / cursor
32 / content
32 / border-image-slice
24 / transition-timing-function
24 / transition-property
24 / transition-duration
24 / transition-delay
24 / transform
24 / text-shadow
24 / quotes
24 / mask-size
24 / mask-repeat
24 / mask-position
24 / mask-origin
24 / mask-mode
24 / mask-image
24 / mask-composite
24 / mask-clip
24 / font-family
24 / filter
24 / box-shadow
24 / border-image-width
24 / border-image-outset
24 / background-size
24 / background-repeat
24 / background-position-y
24 / background-position-x
24 / background-origin
24 / background-image
24 / background-clip
24 / background-blend-mode
24 / background-attachment
24 / animation-timing-function
24 / animation-play-state
24 / animation-name
24 / animation-iteration-count
24 / animation-fill-mode
24 / animation-duration
24 / animation-direction
24 / animation-delay


In particular, clip and clip-path are huge. We should determine a cutoff and start boxing there. Possibly do the same for the computed values. And add an autogenerated test that asserts that the size_of sizes are below this number.

Many of these large numbers are due to Length being large (clip is just 4 lengths and it is 492 bytes large). Even just boxing CalcLengthOrPercentage would reduce numbers significantly here. @wafflespeanut is already refactoring some of this.

cc @bholley @SimonSapin @heycam

h/t @nnethercote for finding this

@Manishearth Manishearth added A-content/css Interacting with CSS from web content (parsing, serializing, introspection) I-perf-bloat Unnecessary memory usage. labels Jan 17, 2017
@Manishearth
Copy link
Member Author

Manishearth commented Jan 17, 2017

These are the sizes for the computed values

216 / clip-path
120 / border-image-source
80 / border-image-width
72 / text-overflow
48 / list-style-image
48 / -moz-binding
40 / grid-row-start
40 / grid-row-end
40 / grid-column-start
40 / grid-column-end
36 / transform-origin
32 / text-emphasis-style
32 / perspective-origin
32 / cursor
32 / content
32 / border-top-right-radius
32 / border-top-left-radius
32 / border-image-slice
32 / border-image-outset
32 / border-bottom-right-radius
32 / border-bottom-left-radius
32 / -moz-outline-radius-topright
32 / -moz-outline-radius-topleft
32 / -moz-outline-radius-bottomright
32 / -moz-outline-radius-bottomleft
24 / transition-timing-function
24 / transition-property
24 / transition-duration
24 / transition-delay
24 / transform
24 / text-shadow
24 / quotes
24 / mask-size
24 / mask-repeat
24 / mask-position
24 / mask-origin
24 / mask-mode
24 / mask-image
24 / mask-composite
24 / mask-clip
24 / font-family
24 / filter
24 / box-shadow
24 / background-size
24 / background-repeat
24 / background-position-y
24 / background-position-x
24 / background-origin
24 / background-image
24 / background-clip
24 / background-blend-mode
24 / background-attachment
24 / animation-timing-function
24 / animation-play-state
24 / animation-name
24 / animation-iteration-count
24 / animation-fill-mode
24 / animation-duration
24 / animation-direction
24 / animation-delay
20 / word-spacing
20 / vertical-align
20 / text-emphasis-color
20 / text-decoration-color
20 / stop-color
20 / scroll-snap-points-y
20 / scroll-snap-points-x
20 / outline-color
20 / lighting-color
20 / flood-color
20 / column-rule-color
20 / border-top-color
20 / border-right-color
20 / border-left-color
20 / border-inline-start-color
20 / border-inline-end-color
20 / border-bottom-color
20 / border-block-start-color
20 / border-block-end-color
20 / background-color
20 / -webkit-text-stroke-color
20 / -webkit-text-fill-color
16 / width
16 / top
16 / text-indent
16 / right
16 / padding-top
16 / padding-right
16 / padding-left
16 / padding-inline-start
16 / padding-inline-end
16 / padding-bottom
16 / padding-block-start
16 / padding-block-end
16 / offset-inline-start
16 / offset-inline-end
16 / offset-block-start
16 / offset-block-end
16 / min-width
16 / min-inline-size
16 / min-height
16 / min-block-size
16 / max-width
16 / max-inline-size
16 / max-height
16 / max-block-size
16 / margin-top
16 / margin-right
16 / margin-left
16 / margin-inline-start
16 / margin-inline-end
16 / margin-bottom
16 / margin-block-start
16 / margin-block-end
16 / left
16 / inline-size
16 / height
16 / flex-basis
16 / color
16 / bottom
16 / block-size



Not as bad, but the computed values add up, unlike the specified values, where only the max is used. However, we never store these computed values in Stylo except for animation. Still, we should fix some of these for Servo memory usage.

@Manishearth
Copy link
Member Author

#15065 tackles this by boxing CalcLOP. #15063 also just makes CalcLOP smaller.

bors-servo pushed a commit that referenced this issue Jan 17, 2017
Cleaning up CalcLengthOrPercentage

<!-- Please describe your changes on the following line: -->

We don't really need enum variants in `CalcLengthOrPercentage`. Given that we already have the information (whether it's `vw`, `ch`, etc.) in the struct fields, we could just store `Option<CSSFloat>` there, and modify our `ToCss` implementation a bit.

cc #15061

r? @Manishearth or anyone interested

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/15063)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Jan 17, 2017
Cleaning up CalcLengthOrPercentage

<!-- Please describe your changes on the following line: -->

We don't really need enum variants in `CalcLengthOrPercentage`. Given that we already have the information (whether it's `vw`, `ch`, etc.) in the struct fields, we could just store `Option<CSSFloat>` there, and modify our `ToCss` implementation a bit.

cc #15061

r? @Manishearth or anyone interested

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/15063)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Jan 17, 2017
Use Box<CalcLengthOrPercentage> in specified values to avoid bloating inline sizes

For #15061

CalcLOP is a large struct, and gets used quite often. While #15063 reduces its size a bit,
it will still be much larger than any of the other variants in the `specified::Length*` types,
so it will still bloat sizes, especially for specified values that contain many lengths.

This change boxes it in the length types, so that it just takes one word.

r? @heycam

<!-- 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/15065)
<!-- Reviewable:end -->
@SimonSapin
Copy link
Member

Thank you for doing this analysis. Boxing data in large enum variants to make the enum smaller sounds good. As you said though, computed values are not typically used in enums so boxing them wouldn’t help much with total memory usage, I think.

bors-servo pushed a commit that referenced this issue Jan 17, 2017
Cleaning up CalcLengthOrPercentage

<!-- Please describe your changes on the following line: -->

We don't really need enum variants in `CalcLengthOrPercentage`. Given that we already have the information (whether it's `vw`, `ch`, etc.) in the struct fields, we could just store `Option<CSSFloat>` there, and modify our `ToCss` implementation a bit.

cc #15061

r? @Manishearth or anyone interested

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/15063)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Jan 17, 2017
Use Box<CalcLengthOrPercentage> in specified values to avoid bloating inline sizes

For #15061

CalcLOP is a large struct, and gets used quite often. While #15063 reduces its size a bit,
it will still be much larger than any of the other variants in the `specified::Length*` types,
so it will still bloat sizes, especially for specified values that contain many lengths.

This change boxes it in the length types, so that it just takes one word.

r? @heycam

<!-- 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/15065)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Jan 28, 2017
Introduce the `NoCalcLength`

<!-- Please describe your changes on the following line: -->

I began this for making the `CalcLengthOrPercentage` represent `LengthOrPercentage` (instead of the enum we already have), but only later did I realize that it will make `LengthOrPercentageOrFoo` types fatty (which is the problem we're trying to avoid - #15061) and so, I dropped that attempt. Along the way, I introduced an internal type for `Length`, for representing all its non-calc variants (which are `Copy`). We could still have this type for the `LengthOrPercentageOrFoo` types which don't really need  `Length` since they already have their own variants for calc.

r? @Manishearth @emilio @SimonSapin or anyone interested

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/15115)
<!-- Reviewable:end -->
bors-servo pushed a commit that referenced this issue Jan 28, 2017
Introduce the `NoCalcLength`

<!-- Please describe your changes on the following line: -->

I began this for making the `CalcLengthOrPercentage` represent `LengthOrPercentage` (instead of the enum we already have), but only later did I realize that it will make `LengthOrPercentageOrFoo` types fatty (which is the problem we're trying to avoid - #15061) and so, I dropped that attempt. Along the way, I introduced an internal type for `Length`, for representing all its non-calc variants (which are `Copy`). We could still have this type for the `LengthOrPercentageOrFoo` types which don't really need  `Length` since they already have their own variants for calc.

r? @Manishearth @emilio @SimonSapin or anyone interested

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/15115)
<!-- Reviewable:end -->
@nox
Copy link
Contributor

nox commented Oct 7, 2017

@SimonSapin This can be considered done, right?

@nox nox added the C-is-this-done It is unclear if the issue has been resolved label Oct 7, 2017
@SimonSapin
Copy link
Member

Yes. We do box some variants of this enum, and have a test to ensure we box exactly those above a certain (configurable) size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/css Interacting with CSS from web content (parsing, serializing, introspection) C-is-this-done It is unclear if the issue has been resolved I-perf-bloat Unnecessary memory usage.
Projects
None yet
Development

No branches or pull requests

3 participants