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

style: Avoid quadratic time serialization of a declaration block. #17315

Merged
merged 3 commits into from Jun 14, 2017

Conversation

@emilio
Copy link
Member

emilio commented Jun 14, 2017

At least when the longhands aren't custom properties.

We should also look into not serializing the style attribute eagerly when it's
not needed... But a lot of code currently rely on attribute values being
dereferenciables to &str, so that's harder to fix.

We should really look into all those vectors around too, but that's probably
less urgent.


This change is Reviewable

At least when the longhands aren't custom properties.

We should also look into not serializing the style attribute eagerly when it's
not needed... But a lot of code currently rely on attribute values being
dereferenciables to &str, so that's harder to fix.

We should really look into all those vectors around too, but that's probably
less urgent.
@highfive
Copy link

highfive commented Jun 14, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/declaration_block.rs
@highfive
Copy link

highfive commented Jun 14, 2017

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

This should fix most of the perf cliffs seen in #17308.

r? @SimonSapin (or anyone else)

@highfive highfive assigned SimonSapin and unassigned cbrewster Jun 14, 2017
@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

cc @glennw

@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

This shaves a good amount of time in the following benchmark (~1s to ~600ms):

<!doctype html>
<script>
var div = document.createElement('div');
div.style.border = "10px solid red";
div.style.position = "absolute";
div.style.top = "10px";
div.style.left = "100px";
div.style.width = "100px";
div.style.height = "100px";

var start = new Date();
for (var i = 0; i < 100000; ++i)
  div.style.cssText;
document.write(new Date() - start);
</script>

But we should aim to be at the ~300/~400ms boundary.

@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

Gah, bad timing pushing to try:

[task 2017-06-14T11:21:01.421797Z] 11:21:01     INFO -  error[E0061]: this function takes 2 parameters but 3 parameters were supplied
[task 2017-06-14T11:21:01.422049Z] 11:21:01     INFO -     --> /home/worker/workspace/build/src/servo/components/style/gecko/values.rs:407:26
[task 2017-06-14T11:21:01.422302Z] 11:21:01     INFO -      |
[task 2017-06-14T11:21:01.422577Z] 11:21:01     INFO -  407 |                   set_name(gecko_value, atom!("none").into_addrefed(), pres_context);
[task 2017-06-14T11:21:01.422881Z] 11:21:01     INFO -      |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 parameters
[task 2017-06-14T11:21:01.423117Z] 11:21:01     INFO -      |
[task 2017-06-14T11:21:01.423371Z] 11:21:01     INFO -     ::: /home/worker/workspace/build/src/obj-firefox/toolkit/library/x86_64-unknown-linux-gnu/release/build/style-a2ebb78ccb6eb042/out/gecko/bindings.rs
[task 2017-06-14T11:21:01.423505Z] 11:21:01     INFO -      |
[task 2017-06-14T11:21:01.423677Z] 11:21:01     INFO -  908 | /     pub fn Gecko_SetCounterStyleToName(ptr: *mut CounterStylePtr,
[task 2017-06-14T11:21:01.423860Z] 11:21:01     INFO -  909 | |                                        name: *mut nsIAtom);
[task 2017-06-14T11:21:01.424040Z] 11:21:01     INFO -      | |___________________________________________________________- defined here
[task 2017-06-14T11:21:01.424263Z] 11:21:01     INFO -  error[E0061]: this function takes 2 parameters but 3 parameters were supplied
[task 2017-06-14T11:21:01.424430Z] 11:21:01     INFO -     --> /home/worker/workspace/build/src/servo/components/style/gecko/values.rs:410:26

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

…tion block.

Concretely we avoid allocating and scanning a temporary vector of longhands not
yet serialized for each shorthand.

This doesn't save a lot of time in Linux, but I bet it's somewhat important on
OSX.
@emilio emilio force-pushed the emilio:quadratic-serialization branch from 2b2eff7 to f8d1bd5 Jun 14, 2017
@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

This is all green :)

@SimonSapin
Copy link
Member

SimonSapin commented Jun 14, 2017

Reviewed 1 of 1 files at r1, 1 of 1 files at r2, 1 of 1 files at r3.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


components/style/properties/properties.mako.rs, line 1342 at r3 (raw file):

    /// The shorthands that this longhand is part of.
    pub fn shorthands(&self) -> &'static [ShorthandId] {

Can this whole method be replaced with self.id().shorthands()?


Comments from Reviewable

By looking at the shorthands, not the other way around, given a longhand uses to
not appear in multiple longhands.

This makes the testcase go to 430ms on my machine.

This could be even faster having a static LonghandIdSet per shorthand, I guess,
but this is not done in this PR.
@emilio emilio force-pushed the emilio:quadratic-serialization branch from f8d1bd5 to 5fbaf6d Jun 14, 2017
@emilio
Copy link
Member Author

emilio commented Jun 14, 2017

Can this whole method be replaced with self.id().shorthands()?

Not literally, but yes if you match on self.id(), so I just did that.

@SimonSapin
Copy link
Member

SimonSapin commented Jun 14, 2017

Looks good!

@bors-servo r+


Reviewed 1 of 1 files at r4.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Jun 14, 2017

📌 Commit 5fbaf6d has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Jun 14, 2017

Testing commit 5fbaf6d with merge d3cc41c...

bors-servo added a commit that referenced this pull request Jun 14, 2017
style: Avoid quadratic time serialization of a declaration block.

At least when the longhands aren't custom properties.

We should also look into not serializing the style attribute eagerly when it's
not needed... But a lot of code currently rely on attribute values being
dereferenciables to &str, so that's harder to fix.

We should really look into all those vectors around too, but that's probably
less urgent.

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

bors-servo commented Jun 14, 2017

@bors-servo bors-servo merged commit 5fbaf6d into servo:master Jun 14, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
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

5 participants
You can’t perform that action at this time.