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

Efficient serialization of programmatically constructed strings #746

Closed
dtolnay opened this issue Feb 3, 2017 · 7 comments
Closed

Efficient serialization of programmatically constructed strings #746

dtolnay opened this issue Feb 3, 2017 · 7 comments

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 3, 2017

A neat idea from @nox that would make a big difference for hyper_serde. We shouldn't need to build the entire string in memory before serializing it.

<nox> Ever thought of doing a SerializeString type parameter, with push_str and methods like that on it?
<nox> Another consequence of doing SerializeString is that we could make that rely on fmt::Write,
<nox> in which case we can do a new default method Serializer::serialize_fmt
<nox> which is better than serializer.serialize_string(stuff.to_string())
<nox> serialize_str(&stuff.to_string()) even.

@nox
Copy link
Contributor

nox commented Feb 3, 2017

The best design would be an associated type with a default value, implementing the associated trait as a String buffer and an end method calling Serializer::serialize_str. Unfortunately, associated type default values are unstable. https://is.gd/Q1DkCh

@dtolnay
Copy link
Member Author

dtolnay commented Feb 4, 2017

I would like to have benchmarks before making a decision on this. Sometimes things that are obvious optimizations turn out to be negligible or even detrimental. In this case conceivably we could be taking something that is a tight loop over here and a tight loop over there and turning it into code that jumps back and forth between two loops in a way that makes the CPU sad.

@nox could you come up with a benchmark to show that this is X% better than the existing approach in some reasonable use case?

@nox
Copy link
Contributor

nox commented Feb 4, 2017

I'm not sure I understand how it could get slower? Which tight loops?

@dtolnay
Copy link
Member Author

dtolnay commented Feb 22, 2017

#778 convinced me that there is plenty of performance to be gained here.

@nox
Copy link
Contributor

nox commented Feb 22, 2017

@dtolnay I think so.

@clarfonthey
Copy link
Contributor

Personally, I think that it'd be nice if we could expose the implementations from #778 somehow so that any crate can use it.

@nox
Copy link
Contributor

nox commented Mar 12, 2017

This can be closed now, right?

@dtolnay dtolnay closed this as completed Mar 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants