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

Use serde_bytes crate #2598

Merged
merged 1 commit into from Apr 4, 2018
Merged

Use serde_bytes crate #2598

merged 1 commit into from Apr 4, 2018

Conversation

@jonleighton
Copy link
Contributor

jonleighton commented Apr 1, 2018

This speeds up serializing and deserializing of binary data.


This change is Reviewable

Cargo.lock Outdated
@@ -395,7 +395,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "freetype"
version = "0.3.0"
version = "0.4.0"

This comment has been minimized.

Copy link
@jonleighton

jonleighton Apr 1, 2018

Author Contributor

This update happened automatically, I believe it is due to d162942

This comment has been minimized.

Copy link
@Eijebong

Eijebong Apr 1, 2018

Member

Doesn't webrender have a CI check for that ?

This comment has been minimized.

Copy link
@jonleighton

jonleighton Apr 1, 2018

Author Contributor

I guess not? Though I don't know, I haven't contributed to webrender before. I've opened a separate PR to fix this: #2599

External(ExternalImageData),
}

mod serde_image_data_raw {

This comment has been minimized.

Copy link
@jonleighton

jonleighton Apr 1, 2018

Author Contributor

This is necessary because we are dealing with an Arc. However, maybe it would be better to patch serde_bytes to support this?

This comment has been minimized.

Copy link
@nox

This comment has been minimized.

Copy link
@dtolnay

dtolnay Apr 1, 2018

Could you propose a more general signature for serde_bytes that could work here?

This comment has been minimized.

Copy link
@jonleighton

jonleighton Apr 1, 2018

Author Contributor

Perhaps not, though I haven't looked into it very closely. Assuming a more general signature is not workable, maybe serde_bytes could also ship serde_bytes_rc/serde_bytes_arc modules though? (Essentially what I've done here, but inside the serde_bytes crate.)

use serde::{Deserializer, Serializer};

pub fn serialize<'a, S: Serializer>(bytes: &'a Arc<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error> {
serde_bytes::serialize(&bytes.as_slice(), serializer)

This comment has been minimized.

Copy link
@dtolnay

dtolnay Apr 1, 2018

There was a missing T: ?Sized in serde_bytes::serialize. I fixed it in 0.10.4 so the & on this line should no longer be necessary.

@jrmuizel
Copy link
Contributor

jrmuizel commented Apr 1, 2018

This speeds up serializing and deserializing of binary data.
@jonleighton jonleighton force-pushed the jonleighton:serde_bytes branch from ef80860 to 74d05cc Apr 3, 2018
@glennw
Copy link
Member

glennw commented Apr 4, 2018

@jrmuizel It looks like this would be used even in Gecko (due to the changes to FontData and the Blob structs), wouldn't it?

Is there any issue with having this enabled for Gecko?

Do we need to do anything further here (benchmarks?) or is this ready to merge?

@jonleighton
Copy link
Contributor Author

jonleighton commented Apr 4, 2018

To give a bit of context to this, I discovered it while profiling the code I was working on for servo/servo#20506

While profiling that code, I was seeing lots of time being spent serializing and deserializing font data bytes when passing them over an IPC channel. I tried using serde_bytes there (i.e. for FontTemplateData in Servo) and it made a big improvement, and I could then see that there was some similar overhead happening when passing bytes to WebRender. I tried building Servo with a local copy of WebRender which used serde_bytes and again saw an improvement when profiling.

(I haven't included serde_bytes in servo/servo#20506 for now since servo/servo@5d5999d mostly negated the need for it and I didn't want to make that PR more complex than it needed to be, but I was still intending to follow up with a PR adding serde_bytes to Servo.)

@glennw
Copy link
Member

glennw commented Apr 4, 2018

@jonleighton Thanks for the info! What does this mean in terms of the Gecko integration which doesn't use the ipc-channel feature in WR?

Does it have any effect at all? Should we be only enabling it in WR when the ipc-channel feature is enabled (e.g. does it increase the binary size for no performance win in that use case)?

@jonleighton
Copy link
Contributor Author

jonleighton commented Apr 4, 2018

If the Gecko integration never serializes/deserializes, then yeah, I guess this code has no effect there.

However, wouldn't the compiler be able to figure out that the code is not used and exclude it from the binary? I'm a bit out of my depth here so I don't know if that is really the case, just struck me as something that might happen.

If that isn't the case, then should WebRender exclude the derive(Deserialize, Serialize) attributes when the ipc feature is not enabled?

@jonleighton
Copy link
Contributor Author

jonleighton commented Apr 4, 2018

If that isn't the case, then should WebRender exclude the derive(Deserialize, Serialize) attributes when the ipc feature is not enabled?

I.e. don't they also bloat the binary?

@glennw
Copy link
Member

glennw commented Apr 4, 2018

Well, Gecko does serialize / deserialize things (such as the display list) - but they are sent over the Gecko IPC mechanism, rather than the rust ipc-channel crate.

So, I guess the question is does this change provide a benefit in that situation? I would think yes, but I just want to make sure that's the case, since @jrmuizel seems to suggest it's only useful if using ipc-channel, per the comment above.

@jonleighton
Copy link
Contributor Author

jonleighton commented Apr 4, 2018

Right, so I also think the answer is yes since serde_bytes speeds up the serializing and deserializing of the data, irrespective of how the serialized data is then moved around.

@glennw
Copy link
Member

glennw commented Apr 4, 2018

That makes sense to me. @jrmuizel Any issues with getting this merged?

@jrmuizel
Copy link
Contributor

jrmuizel commented Apr 4, 2018

Gecko doesn't serialize those structs in normal usage, only the display list. That being said, we probably do serialize them when doing a binary recording (we should probably only support this on Nightly)

I guess it's probably ok to take the extra dependency for now and have a feature flag to disable recording support in a follow up.

@glennw
Copy link
Member

glennw commented Apr 4, 2018

Sounds good, thanks!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Apr 4, 2018

📌 Commit 74d05cc has been approved by glennw

@bors-servo
Copy link
Contributor

bors-servo commented Apr 4, 2018

Testing commit 74d05cc with merge 270e1e9...

bors-servo added a commit that referenced this pull request Apr 4, 2018
Use serde_bytes crate

This speeds up serializing and deserializing of binary data.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2598)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Apr 4, 2018

☀️ Test successful - status-appveyor, status-taskcluster
Approved by: glennw
Pushing 270e1e9 to master...

@bors-servo bors-servo merged commit 74d05cc into servo:master Apr 4, 2018
3 checks passed
3 checks passed
Taskcluster (pull_request) TaskGroup: success
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
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

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