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
Changing blob to use arc pointers in order to limit wasteful copying … #8860
Conversation
// simpler to use version of read_out_buffer | ||
pub fn clone_bytes(&self) -> Vec<u8> { | ||
self.bytes.clone().unwrap_or(vec![]) | ||
self.bytes[start..end].to_vec() |
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 (.to_vec()
) still copies bytes. It looks like this method is used to send Vec<u8>
messages, so it probably can’t simply return &[u8]
instead.
To reduce copying, the Vec<u8>
messages should probably be changed to some reference counted thing. Maybe tendrils? https://github.com/servo/tendril
CC @jdm
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.
I don't know much about tendril and it doesn't really have any good examples of usage afaict. I'm not sure I see any options here; the websocket library accepts a Vec<u8>
, so I believe we're going to have to copy at some point here.
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.
Hmm, I'm wrong - the library does accept &[u8]
, so I think we should make this return &[u8]
instead.
So looking at the code in filereader.rs, I see we'll need another change to avoid copying while dealing with slices appropriately. I propose we extract the buffer and slice data into a separate structure ( |
@jdm that does make sense, I'll see what I can do. |
I pushed a new test commit to show an approach to avoid using However, I do not know if I like the decision to split of the DataSlice/BlobSlice into its own struct, it does not feel very ergonomic to me. I'd prefer to keep those fields in the Blob struct. I guess you can look at the latest commit to see if you agree or not. Also, splitting up the struct caused me to get compiler errors on DataSlice unless I implemented |
For what it's worth, that looks like what I was expecting :) I agree that it would be nice to keep the representation of the data within the containing blob, but our current design forbids us from being able to access the internals of JS-owned values (such as Blobs) on other threads. |
☔ The latest upstream changes (presumably #8867) made this pull request unmergeable. Please resolve the merge conflicts. |
cdafb6f
to
fea9cd9
Compare
d491137
to
a280078
Compare
@jdm What if we had something like: pub enum BlobData {
Owned(Vec<u8>),
Borrowed(JS<Blob>, usize, usize)
} This would allow us to actually track the memory usage of the blobs (by making BlobData's HeapSizeOf implementation return 0 for Borrowed values). |
@nox I'm not sure that really helps if the original blob is inaccessible and only the slice is holding it alive. |
Another thing to keep in mind is that you can |
Oh you are completely right, silly me.
|
☔ The latest upstream changes (presumably #8922) made this pull request unmergeable. Please resolve the merge conflicts. |
a280078
to
4f33b07
Compare
Hi @KiChjang, I am still waiting for any feedback on what needs to be done here. If you have any comments, please let me know Review status: 0 of 7 files reviewed at latest revision, 1 unresolved discussion. Comments from the review on Reviewable.io |
Review status: 0 of 7 files reviewed at latest revision, 1 unresolved discussion. components/script/dom/blob.rs, line 101 [r1] (raw file): Comments from the review on Reviewable.io |
Sorry this fell through the cracks! |
This looks like what I expected! There are a couple changes we can make to improve clarity, and I think we might be able to avoid duplicating the blob contents in the websocket code, though. Reviewed 2 of 5 files at r1, 5 of 5 files at r2. components/script/dom/blob.rs, line 106 [r3] (raw file): components/script/dom/filereader.rs, line 359 [r3] (raw file): components/script/dom/filereader.rs, line 410 [r3] (raw file): components/script/dom/websocket.rs, line 389 [r3] (raw file): Comments from the review on Reviewable.io |
☔ The latest upstream changes (presumably #9160) made this pull request unmergeable. Please resolve the merge conflicts. |
@jdm thank you for the notes, I will take a look at them when I have time tonight and make the appropriate changes |
…ying of byte vector
4f33b07
to
76f689c
Compare
Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed. components/script/dom/blob.rs, line 106 [r3] (raw file): However, since new implies a fresh object, it seems awkward to have to specified None, None, every single time in the constructor. I think we should still keep a separated new_sliced function to avoid this. If you do not agree, I can simply converge the new & new_sliced together. components/script/dom/websocket.rs, line 389 [r3] (raw file): The problem is that we cannot import (script) Blob there, because it would create a circular dependency. I am not sure what you would like to do here. Should we move blob to another crate? Comments from the review on Reviewable.io |
@bors-servo: r+ Reviewed 4 of 4 files at r4. components/script/dom/websocket.rs, line 389 [r3] (raw file): Comments from the review on Reviewable.io |
📌 Commit 76f689c has been approved by |
Changing blob to use arc pointers in order to limit wasteful copying … Fixes #8801. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8860) <!-- Reviewable:end -->
💔 Test failed - mac-rel-css |
⚡ Previous build results for android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-wpt are reusable. Rebuilding only mac-rel-css... |
☀️ Test successful - android, gonk, linux-dev, linux-rel, mac-dev-ref-unit, mac-rel-css, mac-rel-wpt |
Fixes #8801.