-
Notifications
You must be signed in to change notification settings - Fork 60
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
Deserialize Optimizations #82
Conversation
Call Vec::with_capacity(...) when we know what the expected length will be.
When parsing FeatureCollection and Feature JSON objects, avoid a .clone() call.
Thanks @jwass! |
bors r+ |
🔒 Permission denied Existing reviewers: click here to make KodrAus a reviewer |
@frewsxcv looks like bors says no :( @jwass Thanks again for doing this! Historically we've had two serialisation frameworks to support, so optimisation for any particular one took a backseat. That's not the case anymore so we can freely make the |
bors r+ |
🔒 Permission denied Existing reviewers: click here to make urschrei a reviewer |
82: Deserialize Optimizations r=frewsxcv a=jwass Hello, this PR has a couple of parsing optimizations in two commits: - When creating `Vec`s for GeoJSON objects, initialize with `Vec::with_capacity(...)` since we know what size to expect. - Avoid a couple of critical `clone()` calls. Currently, when parsing from a string, the entire JSON value is cloned after it's parsed, then each Feature is cloned again when parsing a FeatureCollection. I believe this is due to serde_json's `as_array()` and `as_object()` functions returning borrowed references. I avoid those calls by doing the `match` directly (by adding the `_owned` macros), which allows moving those objects without cloning. I tested this on a release target on a ~330MB GeoJSON file (all Polygons), current master parses in about 18 seconds. After these changes, it takes under 10s. Parsing using just serde_json is about 8.2 s. I'm pretty new to Rust so feel free to let me know if these changes are a bad idea -- or any other suggestions.
Build succeeded |
Hello, this PR has a couple of parsing optimizations in two commits:
Vec
s for GeoJSON objects, initialize withVec::with_capacity(...)
since we know what size to expect.clone()
calls.Currently, when parsing from a string, the entire JSON value is cloned after it's parsed, then each Feature is cloned again when parsing a FeatureCollection. I believe this is due to serde_json's
as_array()
andas_object()
functions returning borrowed references. I avoid those calls by doing thematch
directly (by adding the_owned
macros), which allows moving those objects without cloning.I tested this on a release target on a ~330MB GeoJSON file (all Polygons), current master parses in about 18 seconds. After these changes, it takes under 10s. Parsing using just serde_json is about 8.2 s.
I'm pretty new to Rust so feel free to let me know if these changes are a bad idea -- or any other suggestions.