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

Support zero-copy reading in serde deserializer #328

Closed
stevenroose opened this issue Oct 20, 2021 · 3 comments · Fixed by #509
Closed

Support zero-copy reading in serde deserializer #328

stevenroose opened this issue Oct 20, 2021 · 3 comments · Fixed by #509
Labels
enhancement optimization Issues related to reducing time needed to parse XML or to memory consumption serde Issues related to mapping from Rust types to XML

Comments

@stevenroose
Copy link

It seems that the current usage of Reader requires you to copy a lot of bytes from the reader into the buffer. Why is there no way to get access to slices into the original bytes that were provided?

serde, and serde_json allow for Deserializing borrowed data by borrowing into the original content. I can't find out if quick_xml supports it, but I don't think so.

Could I f.e. parse an XML like this:

<map>
  <entry>
    <key>test</key>
    <value>testvalue</value>
  </entry>
</map>

Into a HashMap<&str, &str>? Where the keys and values are references into the original string passed into Reader::from_str.

From the method signature

pub fn read_event<'a, 'b>(
    &'a mut self,
    buf: &'b mut Vec<u8>
) -> Result<Event<'b>>

it seems like all data the events contain is first copied into the buffer and then references there...

@stevenroose
Copy link
Author

I just noticed that read_event_unbuffered exists, but it's not documented on docs.rs. Also, the read_event default forwards to the buffered version. I'm kind of thinking this default is a bit misleading, it would be nice if there was no default. (Because it's not really possible to have a default that changed depending on whether buffered is available, I think...

@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML optimization Issues related to reducing time needed to parse XML or to memory consumption labels May 21, 2022
@dralley
Copy link
Collaborator

dralley commented Jul 29, 2022

read_event() now behaves as read_event_unbuffered() did (although not released yet)

@dralley dralley closed this as completed Jul 29, 2022
@Mingun
Copy link
Collaborator

Mingun commented Jul 30, 2022

Well, serde part are still not fully zero-copy, and the original request seems to requests this for serde

@Mingun Mingun reopened this Jul 30, 2022
@Mingun Mingun changed the title Support zero-copy reading Support zero-copy reading in serde deserializer Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement optimization Issues related to reducing time needed to parse XML or to memory consumption serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants