-
Notifications
You must be signed in to change notification settings - Fork 279
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
Conversation
There was a problem hiding this 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.
webrender_api/src/display_list.rs
Outdated
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
unsafe { | ||
if self.buf.offset(buf.len() as isize) > self.end { | ||
panic!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely need a message.
There was a problem hiding this comment.
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 buf
s here is confusing. (I stared at this way too long)
webrender_api/src/display_list.rs
Outdated
@@ -179,6 +179,45 @@ fn skip_slice<T: for<'de> Deserialize<'de>>( | |||
(range, count) | |||
} | |||
|
|||
struct UnsafeReader<'a: 'b, 'b> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
e0afa31
to
370ff2f
Compare
With this version and an updated bincode (bincode-org/bincode#207) I go from 140fps to 200fps on my gmail yaml |
370ff2f
to
fc34ec0
Compare
fc34ec0
to
ea1c1cf
Compare
webrender_api/src/display_list.rs
Outdated
@@ -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 |
There was a problem hiding this comment.
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
webrender_api/src/display_list.rs
Outdated
unsafe { | ||
if self.start.offset(buf.len() as isize) > self.end { | ||
panic!(); | ||
} |
There was a problem hiding this comment.
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");
webrender_api/src/display_list.rs
Outdated
// 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> { |
There was a problem hiding this comment.
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?
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.
ea1c1cf
to
9818e4d
Compare
@bors-servo r=Gankro |
📌 Commit 9818e4d has been approved by |
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 -->
☀️ Test successful - status-appveyor, status-travis |
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. |
I haven't yet tested how much this improves deserialization performance but it should be noticeable.
This change is