You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using viewport percentage lengths (e.g. vh, vw) causes unnecessary style recalc on resize #10104
A-content/cssInteracting with CSS from web content (parsing, serializing, introspection)C-assignedThere is someone working on resolving the issueE-more-complexVariable effort required; may require a mentor. Recommended solution is clearly described in the issI-perf-slowUnnecessary performance degredation.
As mentioned in #9876 (comment), Servo currently does more work than necessary to recalculate vh/vw/vmin/vmax units when the window size changes. Currently, during parsing, if a stylesheet contains any of these viewport percentage units, we add a dirty_on_viewport_size_change to the stylesheet. When the viewport size changes, if any stylesheet has this flag set, we dirty all nodes and recalculate their styles.
Instead, we could dirty only nodes that match rules containing viewport percentages. During selector matching, Stylist::push_applicable_declarations could set a flag on any node whose applicable declarations contain one of these units. This would require adding a method to DeclaredValue and the various SpecifiedValue types that determines whether the value includes a viewport percentage length.
Hi @roysohan. Checkout wiki and especially Quickstart to Hacking Servo. For any questions regarding Servo, #servo IRC channel on irc.mozilla.org is a fine place. For Rust related questions there is #rust and #rust-beginner channels.
Note: This issue is tagged "less easy", which means that it might not be suitable for a brand new contributor, but could be good as a next step after one or more easy issues. This is mainly because it could require making a large number of small changes; it will probably be tedious but hopefully not too complicated. If you are patient and have enough time, you could probably start out with this issue.
One way to solve this issue would be to add a trait for asking whether a given CSS value has any viewport percentage lengths:
Implement this trait for the Length type, returning true if it is a Length::ViewportPercentage and false otherwise. Then implement it for any other types in style::values::specified that can contain Length values; it should return true if any field of the type contains a Length::ViewportPercentage. For example:
Next, look at each SpecifiedValue type. (Many of these are aliases to common types, so there are fewer than it appears.) If the type has any fields that might contain Length values, then it should impl the trait and return true if any of those values is a Length::ViewportPercentage:
Once all of those impls are written, we can impl HasViewportPercentage for PropertyDeclaration. The implementation will look something like this:
implHasViewportPercentageforPropertyDeclaration{fnhas_viewport_percentage(&self) -> bool{match*self{// For the properties whose SpecifiedValues can contain lengths,// check the SpecifiedValue:MarginTop(DeclaredValue::Value(val)) => val.has_viewport_percentage()),MarginRight(DeclaredValue::Value(val)) => val.has_viewport_percentage()),MarginBottom(DeclaredValue::Value(val)) => val.has_viewport_percentage()),MarginLeft(DeclaredValue::Value(val)) => val.has_viewport_percentage()),PaddingTop(DeclaredValue::Value(val)) => val.has_viewport_percentage()),/// ...etc.// For other properties, return false:
_ => false,}}}
Fortunately we don't need to write or maintain this giant match expression by hand. Instead, it can be generated by the Mako preprocessor from source code in properties.mako.rs. This will require adding a new boolean field to the each "longhand" property in the Mako template, specifying whether it implements HasViewportPercentage.
Whew. I hope that's enough for someone to get started. Once you've done all that, you will still need to add code in selector_matching.rs to flag elements that match rules containing viewport percentages. I can answer questions about that part when we get there.
I am quite busy, but will try starting to contribute, any hints on which file to start.
Also I am low on bandwidth, so can you suggest how to contribute in low bandwidth condition
I am a college student, and I have exams, I have started learning rust as a hobby, and someone suggested on rust irc channels that I should be contributing to servo for better understanding.
So the problem is I cannot commit myself. I am extremely sorry for that.
But I will contribute little by little. And this is my first time. So I need your guide and support on where to start, how to do, and which files to edit. I think slowly under your guidance I may learn something.
I apologise for not being able to commit myself fully.
Also I am a total beginner at this. I learnt programming upto high school, know little about java and c,ie some basic programming.
If I understand well, the HasViewportPercentage trait is used to easily identify which node is currently using a vh/vw unit so we must only dirty these nodes when the viewport size change ?
If I understand well, the HasViewportPercentage trait is used to easily identify which node is currently using a vh/vw unit so we must only dirty these nodes when the viewport size change ?
Yes.
And dirtying these nodes is done somewhere in selector_matching.rs ?
During selector matching, either push_applicable_declarations or one of the functions that calls it (style::traversal::recalc_style_at might be the easiest place to do this) should set this flag on any node whose applicable declarations contain a viewport percentage or whose parent has the flag set, and should clear the flag otherwise. This will require adding a new DIRTY_ON_VIEWPORT_SIZE_CHANGE flag to the script::dom::node::NodeFlags type, and a new method to set this flag in the style::dom::TNode trait. (The new method will be very similar to the TNode::set_dirty method.)
Then, finally, in LayoutThread::handle_reflow, instead of marking all nodes as dirty when the viewport size changes, call a new function that only dirties nodes with this new flag.
I'll finish implementing the actual HasViewportPercentage trait for properties that may use viewport length, then I'll actually set them and use them in recalc_style_at
A-content/cssInteracting with CSS from web content (parsing, serializing, introspection)C-assignedThere is someone working on resolving the issueE-more-complexVariable effort required; may require a mentor. Recommended solution is clearly described in the issI-perf-slowUnnecessary performance degredation.
Activity
Don't re-add stylesheets to recompute vw/vh lengths
SimonSapin commentedon Mar 22, 2016
The descendants of these nodes may also be affected through CSS inheritance, and likely need to be dirtied as well.
Auto merge of #10105 - mbrubeck:dirty-viewport-percentages, r=SimonSapin
roysohan commentedon Mar 28, 2016
I am a beginner but i want to contribute, and the folks said that e-easy tags are the best place to start. So how do I contribute to this issue.
jrasanen commentedon Mar 29, 2016
Hi @roysohan. Checkout wiki and especially Quickstart to Hacking Servo. For any questions regarding Servo, #servo IRC channel on irc.mozilla.org is a fine place. For Rust related questions there is #rust and #rust-beginner channels.
mbrubeck commentedon Mar 29, 2016
Note: This issue is tagged "less easy", which means that it might not be suitable for a brand new contributor, but could be good as a next step after one or more easy issues. This is mainly because it could require making a large number of small changes; it will probably be tedious but hopefully not too complicated. If you are patient and have enough time, you could probably start out with this issue.
One way to solve this issue would be to add a trait for asking whether a given CSS value has any viewport percentage lengths:
Implement this trait for the Length type, returning
trueif it is a Length::ViewportPercentage andfalseotherwise. Then implement it for any other types in style::values::specified that can contain Length values; it should returntrueif any field of the type contains a Length::ViewportPercentage. For example:Next, look at each SpecifiedValue type. (Many of these are aliases to common types, so there are fewer than it appears.) If the type has any fields that might contain Length values, then it should impl the trait and return
trueif any of those values is aLength::ViewportPercentage:Once all of those impls are written, we can impl HasViewportPercentage for PropertyDeclaration. The implementation will look something like this:
Fortunately we don't need to write or maintain this giant
matchexpression by hand. Instead, it can be generated by the Mako preprocessor from source code in properties.mako.rs. This will require adding a new boolean field to the each "longhand" property in the Mako template, specifying whether it implements HasViewportPercentage.Whew. I hope that's enough for someone to get started. Once you've done all that, you will still need to add code in selector_matching.rs to flag elements that match rules containing viewport percentages. I can answer questions about that part when we get there.
KiChjang commentedon Mar 30, 2016
@roysohan Could you confirm that you are currently working on this issue?
roysohan commentedon Mar 31, 2016
I am quite busy, but will try starting to contribute, any hints on which file to start.
Also I am low on bandwidth, so can you suggest how to contribute in low bandwidth condition
I am a college student, and I have exams, I have started learning rust as a hobby, and someone suggested on rust irc channels that I should be contributing to servo for better understanding.
So the problem is I cannot commit myself. I am extremely sorry for that.
But I will contribute little by little. And this is my first time. So I need your guide and support on where to start, how to do, and which files to edit. I think slowly under your guidance I may learn something.
I apologise for not being able to commit myself fully.
Also I am a total beginner at this. I learnt programming upto high school, know little about java and c,ie some basic programming.
jdm commentedon Mar 31, 2016
Note - @roysohan is looking into other issues instead, so this one is still available.
Shiroy commentedon Apr 3, 2016
I'm working on this issue.
If I understand well, the
HasViewportPercentagetrait is used to easily identify which node is currently using a vh/vw unit so we must only dirty these nodes when the viewport size change ?And dirtying these nodes is done somewhere in selector_matching.rs ?
mbrubeck commentedon Apr 4, 2016
Yes.
During selector matching, either
push_applicable_declarationsor one of the functions that calls it (style::traversal::recalc_style_atmight be the easiest place to do this) should set this flag on any node whose applicable declarations contain a viewport percentage or whose parent has the flag set, and should clear the flag otherwise. This will require adding a newDIRTY_ON_VIEWPORT_SIZE_CHANGEflag to thescript::dom::node::NodeFlagstype, and a new method to set this flag in thestyle::dom::TNodetrait. (The new method will be very similar to theTNode::set_dirtymethod.)Then, finally, in
LayoutThread::handle_reflow, instead of marking all nodes as dirty when the viewport size changes, call a new function that only dirties nodes with this new flag.16 remaining items
jdm commentedon May 3, 2016
Ok, just let us know if you start working on this again!
shinglyu commentedon May 23, 2016
I'm interested in this.
KiChjang commentedon May 23, 2016
Have at it!
shinglyu commentedon May 24, 2016
(@shinglyu add to my dashboard)
jdm commentedon Jun 21, 2016
@shinglyu Is this something you're still working on?
shinglyu commentedon Jun 22, 2016
Yes, sorry for the delay
shinglyu commentedon Jun 22, 2016
I already have a rough picture of how to do it, but @Shiroy 's patch does not apply on the latest master, so I have to do it manually.
shinglyu commentedon Jun 23, 2016
Status: I reused part of @Shiroy 's patch, and followed @SimonSapin 's suggestion to create a marker trait for
NoViewportPercentage.https://github.com/shinglyu/servo/commits/viewport-percent-recalc
I'll finish implementing the actual
HasViewportPercentagetrait for properties that may use viewport length, then I'll actually set them and use them inrecalc_style_atshinglyu commentedon Jun 27, 2016
I have a patch now: master...shinglyu:viewport-percent-recalc
I still need to do some testing and profiling to make sure it does improve the performance.
Auto merge of #11890 - shinglyu:viewport-percent-recalc, r=mbrubeck
Auto merge of #11890 - shinglyu:viewport-percent-recalc, r=mbrubeck
Auto merge of #11890 - shinglyu:viewport-percent-recalc, r=mbrubeck