-
Notifications
You must be signed in to change notification settings - Fork 472
Performance: formatting float/double for json and text formats #392
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
Comments
Related: The other problem with |
Hmmm.... Looks like the exactness problem was partially addressed in swiftlang/swift#348 ( |
ahmed-osama-saad
pushed a commit
to ahmed-osama-saad/swift-protobuf
that referenced
this issue
Oct 12, 2023
ahmed-osama-saad
pushed a commit
to ahmed-osama-saad/swift-protobuf
that referenced
this issue
Oct 12, 2023
Expose characteristic properties
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Writing float and double values to JSON or text format is significantly slower than it should be.
The original code used
String(_: Double)
to convert doubles to String, and then converted the String to UTF8 to append to the output. PR #391 changes this to directly invoke the C librarystrtod
andvsnprintf
to parse and format doubles, respectively.The direct use of
strtod
worked very well, butvsnprintf
requires using Swift'sCVarArg
facility; this involves creating intermediate objects that we usually manage to avoid. If we could avoid using varargs in this way, we should see a sizable performance improvement. Unfortunately, the standard C library does not expose a function for formatting float/double that doesn't use varargs.The text was updated successfully, but these errors were encountered: