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
Contributor

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 left a comment

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!();

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

Definitely need a message.

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

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> {

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

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

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

Also why it's desirable.

@jrmuizel jrmuizel force-pushed the jrmuizel:unsafe-reader branch from e0afa31 to 370ff2f Oct 10, 2017
@jrmuizel
Copy link
Contributor Author

jrmuizel commented Oct 10, 2017

With this version and an updated bincode (servo/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
@jrmuizel jrmuizel force-pushed the jrmuizel:unsafe-reader branch from 370ff2f to fc34ec0 Oct 10, 2017
@jrmuizel jrmuizel force-pushed the jrmuizel:unsafe-reader branch from fc34ec0 to ea1c1cf 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

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

"gives" at end of line is junk

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

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

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> {

This comment has been minimized.

@Gankra

Gankra Oct 10, 2017

Contributor

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 jrmuizel force-pushed the jrmuizel:unsafe-reader branch from ea1c1cf to 9818e4d Oct 10, 2017
@jrmuizel
Copy link
Contributor Author

jrmuizel commented Oct 10, 2017

@bors-servo r=Gankro

@bors-servo
Copy link
Contributor

bors-servo commented Oct 10, 2017

📌 Commit 9818e4d has been approved by Gankro

@bors-servo
Copy link
Contributor

bors-servo commented Oct 10, 2017

Testing commit 9818e4d with merge aee99d4...

bors-servo added 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

bors-servo commented Oct 10, 2017

☀️ 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
4 checks passed
4 checks passed
Taskcluster (pull_request) TaskGroup: success
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@hherman1
Copy link

hherman1 commented Oct 20, 2017

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 added 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
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.