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

Improve deserialization performance #1834

Merged
merged 2 commits into from
Oct 10, 2017
Merged

Conversation

jrmuizel
Copy link
Collaborator

@jrmuizel jrmuizel commented Oct 10, 2017

I haven't yet tested how much this improves deserialization performance but it should be noticeable.


This change is Reviewable

Copy link
Contributor

@Gankra Gankra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my comments for now; I'll re-review when you've cleaned it up a bit.

fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
unsafe {
if self.buf.offset(buf.len() as isize) > self.end {
panic!();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely need a message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the presence of two bufs here is confusing. (I stared at this way too long)

@@ -179,6 +179,45 @@ fn skip_slice<T: for<'de> Deserialize<'de>>(
(range, count)
}

struct UnsafeReader<'a: 'b, 'b> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs for why it's unsafe, and why that's fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why it's desirable.

@jrmuizel
Copy link
Collaborator Author

jrmuizel commented Oct 10, 2017

With this version and an updated bincode (bincode-org/bincode#207) I go from 140fps to 200fps on my gmail yaml

@jrmuizel jrmuizel changed the title WIP: Improve deserialization performance Improve deserialization performance Oct 10, 2017
@@ -525,6 +527,73 @@ fn serialize_fast<T: Serialize>(vec: &mut Vec<u8>, e: &T) {
debug_assert!(((w.0 as usize) - (vec.as_ptr() as usize)) == vec.len());
}

// This uses a (start, end) representation instead of (start, len) so that
// only need to update a single field as we read through it. This gives
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"gives" at end of line is junk

unsafe {
if self.start.offset(buf.len() as isize) > self.end {
panic!();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if should just be

assert!(self.start.offset(buf.len() as isize) <= self.end, "UnsafeReader: wrote past end of target");

// only need to update a single field as we read through it. This gives
// makes it easier for llvm to understand what's going on. (https://github.com/rust-lang/rust/issues/45068)
// we update the slice only once we're done reading
struct UnsafeReader<'a: 'b, 'b> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually totally save to use, so maybe just ExactReader?

@glennw
Copy link
Member

glennw commented Oct 10, 2017

Wow, that's a nice FPS improvement!

@Gankra
Copy link
Contributor

Gankra commented Oct 10, 2017

r=me with requested changes

With this change I go from 140fps to 200fps on my gmail yaml.
@jrmuizel
Copy link
Collaborator Author

@bors-servo r=Gankro

@bors-servo
Copy link
Contributor

📌 Commit 9818e4d has been approved by Gankro

@bors-servo
Copy link
Contributor

⌛ Testing commit 9818e4d with merge aee99d4...

bors-servo pushed a commit that referenced this pull request Oct 10, 2017
Improve deserialization performance

I haven't yet tested how much this improves deserialization performance but it should be noticeable.

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

☀️ Test successful - status-appveyor, status-travis
Approved by: Gankro
Pushing aee99d4 to master...

@bors-servo bors-servo merged commit 9818e4d into servo:master Oct 10, 2017
@hherman1
Copy link

Hi! Rust noob here,

Would it make sense to make this available in the rust stl if it’s so much faster than the built in?

glennw pushed a commit to glennw/saltfs that referenced this pull request Oct 20, 2017
bors-servo pushed a commit to servo/saltfs that referenced this pull request Oct 20, 2017
Add Gankro to WR reviewers list.

Some reviews in WR that Gankro has worked on:

servo/webrender#1830
servo/webrender#1799
servo/webrender#1834
servo/webrender#1664

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

Gankra commented Oct 20, 2017

Probably not, for a few reasons. It's specific to how we're using serde (which isn't part of std), and is also unsound if you're not using serde exactly like us. Basically we're relying on the fact that all of our serialization code is machine-generated, so we can't ever get expected and actual size wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants