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

Update ToWkt::write_wkt to not buffer string #126

Merged
merged 6 commits into from
Nov 27, 2024

Conversation

kylebarron
Copy link
Member

@kylebarron kylebarron commented Nov 26, 2024

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.
  • I ran cargo fmt

This avoids buffering when writing WKT to std::io::Write. It's considerably faster:

geo: write small wkt    time:   [570.44 ns 573.74 ns 578.31 ns]
                        change: [-30.487% -29.975% -29.481%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 9 outliers among 100 measurements (9.00%)
  1 (1.00%) high mild
  8 (8.00%) high severe

geo: write big wkt      time:   [2.0220 ms 2.0300 ms 2.0405 ms]
                        change: [-19.849% -19.214% -18.603%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) high mild
  4 (4.00%) high severe

@kylebarron kylebarron marked this pull request as draft November 26, 2024 21:13
@kylebarron kylebarron marked this pull request as ready for review November 26, 2024 23:03
@kylebarron kylebarron changed the title Update geo_types writer integration to avoid intermediate representation Update ToWkt::write_wkt to not buffer string Nov 26, 2024
@kylebarron
Copy link
Member Author

I updated the PR description. This is actually considerably faster than collecting a string and then writing that to the output buffer.

Copy link
Member Author

@kylebarron kylebarron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say I'm content with keeping the direct APIs as using std::fmt::Write because we know we're writing UTF8 content. Otherwise you'd have to write to a Vec<u8> and then parse that back to a String (or maybe trust ourselves and use from_utf8_unchecked?)

Comment on lines 17 to 18
// Sadly, this will lose the content of the error when mapping to std::fmt::Error
self.0.write(s.as_bytes()).map_err(|_| std::fmt::Error)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loss of error content is unfortunate but I'm not sure of a good way around this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #129

@michaelkirk michaelkirk merged commit 94c32cd into main Nov 27, 2024
1 check passed
@michaelkirk michaelkirk deleted the kyle/update-geo-types-writer branch November 27, 2024 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants