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

Serialize style attributes on demand… #17476

Closed
wants to merge 3 commits into from
Closed

Serialize style attributes on demand… #17476

wants to merge 3 commits into from

Conversation

@SimonSapin
Copy link
Member

SimonSapin commented Jun 22, 2017

… rather than every time that CSSOM Element.style is modified. Results are not cached in this PR. We could add APIs that work with &mut AttrValue rather than &AttrValue to add some caching.

CC #17399


This change is Reviewable

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 22, 2017

@bors-servo try

@glennw, does this help with performance issues in #17399?

@bors-servo
Copy link
Contributor

bors-servo commented Jun 22, 2017

Trying commit af24044 with merge 41d7591...

bors-servo added a commit that referenced this pull request Jun 22, 2017
Serialize style attributes on demand…

… rather than every time that CSSOM `Element.style` is modified. Results are *not* cached in this PR. We could add APIs that work with `&mut AttrValue` rather than `&AttrValue` to add some caching.

CC #17399

<!-- 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/17476)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 22, 2017

💔 Test failed - linux-dev

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 22, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jun 22, 2017

Trying commit b599b2b with merge 86ae135...

bors-servo added a commit that referenced this pull request Jun 22, 2017
Serialize style attributes on demand…

… rather than every time that CSSOM `Element.style` is modified. Results are *not* cached in this PR. We could add APIs that work with `&mut AttrValue` rather than `&AttrValue` to add some caching.

CC #17399

<!-- 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/17476)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 22, 2017

💔 Test failed - linux-rel-wpt

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 22, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Jun 22, 2017

Trying commit 921d142 with merge 9743ab4...

bors-servo added a commit that referenced this pull request Jun 22, 2017
Serialize style attributes on demand…

… rather than every time that CSSOM `Element.style` is modified. Results are *not* cached in this PR. We could add APIs that work with `&mut AttrValue` rather than `&AttrValue` to add some caching.

CC #17399

<!-- 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/17476)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 22, 2017

💔 Test failed - linux-rel-wpt

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 22, 2017

Lots of AttrValue::as_* calls panic because the value is not of the expected variants. We might need a more systematic way to track what attribute of what element is supposed to be of what variant, and enforce it at various entry points…

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 23, 2017

@metajack @glennw I’m gonna put this on hold for now. Glenn’s work-around will be enough for next week’s demo, right?

@metajack
Copy link
Contributor

metajack commented Jun 23, 2017

Yes, the hack is sufficient for next week.

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 23, 2017

Previously, all variants of the AttrValue enum contained a String of Atom so we could always get (through deref) a &str out of a AttrValue. This PR removes the String from the AttrValue::Declaration to make it generated on demand, and removes the Deref impl.

That means everything that relied on deref needs to do something else. AttrValue already had methods like as_tokens(&self) -> &[Atom] that assume the enum is of a particular variant (in this case AttrValue::TokenList) and panic if it’s not. In that, they’re similar to unwrap. This PR replaces uses of deref with calls to these methods all over the place. But the enum often ends up with a different variant than the one expected, so many tests fail with panics.

I could play whack-a-mole until the test suite passes, but I’m worried that this would leave more panics waiting to happen. So if we want keep pursuing wide usage of as_tokens and friends, I think we need to more systematically track which AttrValue is of which variant. We already have parse_plain_attribute that does it based on element type + attribute name, but not all values go through that code path. We’d need to enforce that more systematically.

For code that needs to deal with potentially any variant, the serialize method returns String. But since AttrValue::Declaration’s contents is protected by a document-wide lock, serialize takes a closure that is only called in the Declaration case to acquire that lock (or use a pre-acquired guard). Using it everywhere would be quite verbose.

Another idea might be to add a method that panics, but only in the AttrValue::Declaration case which is used more rarely.

@pcwalton
Copy link
Contributor

pcwalton commented Jun 24, 2017

Could we use lazy-init as a more straightforward way to do this? I started doing this and it seemed quite simple. It lets us keep the Deref implementation, and, as an added bonus, it gives us caching.

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 24, 2017

Looks like lazy-init is a one-time thing, where as a PropertyDeclarationBlock is mutable. Modifying it invalidates a previously-serialized String, which needs to be dropped safely somehow.

@pcwalton
Copy link
Contributor

pcwalton commented Jun 24, 2017

In that case, we should definitely decide what to do here. I don't like leaving good demo performance gated on temporary hacks; I've been burned by this too many times as folks try our demos and call us out.

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 25, 2017

I’ll try to hack something with a RwLock<Option<String>> or something like that.

@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 27, 2017

When writing my last comment I forgot that accessing the PropertyDeclarationBlock requires a reference to the per-document lock, so we’re back with the tradeoff from #17476 (comment)

@bors-servo
Copy link
Contributor

bors-servo commented Jul 15, 2017

The latest upstream changes (presumably #17744) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Sep 14, 2017

This does not appear to be going anywhere.

@jdm jdm closed this Sep 14, 2017
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.