buffer: use std::to_chars for serializing doubles#29500
buffer: use std::to_chars for serializing doubles#29500jmarantz merged 2 commits intoenvoyproxy:mainfrom
Conversation
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
| for (const Stats::ParentHistogram::Bucket& bucket : buckets) { | ||
| response.addFragments( | ||
| {delim, absl::StrCat(bucket.lower_bound_, ",", bucket.width_, ":", bucket.count_)}); | ||
| response.addFragments({delim, absl::StrFormat("%.15g,%.15g:%lu", bucket.lower_bound_, |
There was a problem hiding this comment.
Note: I did not use the new mechanism to serialize a double in this case because it did not make the benchmark run faster, but did make the code more verbose and harder to read. However I realized we were dropping precision on the text histogram so I wanted to fix it.
|
/retest |
1 similar comment
|
/retest |
|
On Linux x86_64 I'm getting build errors Is compiling fine on MacOS aarch64. Still building on Linux aarch64. Edit - this is using Google RBE /cc @jmarantz |
|
interesting; it did pass CI. Can you tell from your logs exactly what compiler was being used? |
|
It also passes for me with RBE using command Where my .bazelrc.remote has these lines: I'm wondering if somehow your toolchain is not quite consistent with what's in CI or my RBE. |
|
Checking now but have been building with my setup for ages without issues |
|
Well this PR does add some dependency on the C++ runtime supporting to_chars with a double. On Apple and in GCC this is not the case and a different strategy is selected via ifdef. So I suspect you have a version of clang setup somehow which does not have that to_chars support. Can you tell me what version you are using? We could add another ifdef clause, but as CI is working I'd prefer not rolling back. |
|
If you scroll in the error is says it is using clang 14. I'm invoking my RBE build with This is a super old invocation I put together with Matt and Harvey when I was onboarded to RBE. Will try some other options. Update - looks like my invocation was old and |
|
great. I guess maybe your library was from an earlier version of clang and this PR makes it more sensitive to that. If this continues to be a paper-cut I'll write a PR to test library-version >= 14 and use the slower serializer for earlier libraries, but it will be annoying to test :) |
|
I am building locally in the edit: interesting that while it is invoking |
|
^ this is resolved by running I'm not sure which minimum version of libc++ works, but currently the I will open a PR to add libstdc++-11-dev to the |
Commit Message: A performance regression was found in a late commit as part of #28988 where we switched from a low-precision fast serialization of doubles (absl::StrCat) to a high-precision slow serialization of doubles (absl::StrFormat("%.15g", ...). This resolves that issue using std::to_chars which is faster than absl::StrCat and is also high precision. The downside is it doesn't work on all platforms, so an intermediate high-precision medium-speed solution was found for Apple and GCC. The serialize-double-to-buffer functionality is moved out of Json::Streamer and into a new Buffer::Util namespace.
Latest Json histogram serialization performance:
Additional Description:
Risk Level: low
Testing: /test/common/json/... test/common/buffer //test/server/admin/...
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a