Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImprove deserialization performance #1834
Conversation
|
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
With this version and an updated bincode (servo/bincode#207) I go from 140fps to 200fps on my gmail yaml |
| @@ -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.
This comment has been minimized.
| unsafe { | ||
| if self.start.offset(buf.len() as isize) > self.end { | ||
| panic!(); | ||
| } |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
|
Wow, that's a nice FPS improvement! |
|
r=me with requested changes |
With this change I go from 140fps to 200fps on my gmail yaml.
|
@bors-servo r=Gankro |
|
|
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 -->
|
|
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? |
Some reviews in WR that Gankro has worked on: servo/webrender#1830 servo/webrender#1799 servo/webrender#1834 servo/webrender#1664
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 -->
|
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. |
jrmuizel commentedOct 10, 2017
•
edited by larsbergstrom
I haven't yet tested how much this improves deserialization performance but it should be noticeable.
This change is