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

feat: Integration with fast_float #1170

Draft
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

swaingotnochill
Copy link

@swaingotnochill swaingotnochill commented Oct 15, 2024

See #1069

This is a draft pull request and the work is in progress.

The goal of this is to get timely feedback and reviews from the reviewers.

TODO:

  • Create the wrapper and archive it.
  • [] Replace it with strtod.
  • [] Benchmark it.
  • [] Run it on different platforms.

cc: @madolson @PingXie

@swaingotnochill swaingotnochill marked this pull request as draft October 15, 2024 00:48
@madolson
Copy link
Member

@parthpatel FYI.

If possible we would rather not take the C++ dependency, although that might be doable. Do you know how much effort it would be to port the code into C. The templating code seems very generic, but I don't think we need all the flexibility it is providing.

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.72%. Comparing base (36d438b) to head (8a54ec2).
Report is 12 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1170      +/-   ##
============================================
+ Coverage     70.69%   70.72%   +0.02%     
============================================
  Files           114      114              
  Lines         61693    63006    +1313     
============================================
+ Hits          43611    44558     +947     
- Misses        18082    18448     +366     

see 97 files with indirect coverage changes

@swaingotnochill
Copy link
Author

@madolson do you suggest to port the cpp code to c rather than use fast_float?

@parthpatel
Copy link
Member

@parthpatel FYI.

If possible we would rather not take the C++ dependency, although that might be doable. Do you know how much effort it would be to port the code into C. The templating code seems very generic, but I don't think we need all the flexibility it is providing.

Even if we remove the templating for character type, we still have "class" and "std::" library references. With little more effort, we should be able to remove it. But we won't be able to merge fixes or changes from upstream. In my opinion, we should start with fast_float library as a sub-module (instead of copying the code) and if we run into C++ related issues, then we can still internally change the implementation.

@@ -0,0 +1,3869 @@
// fast_float by Daniel Lemire
Copy link
Member

Choose a reason for hiding this comment

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

if you embed this file, and in future there are bugfixes to this library, how do we track it? is it possible to use submodules for this https://git-scm.com/book/en/v2/Git-Tools-Submodules ?

Copy link
Author

Choose a reason for hiding this comment

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

The proper scenario is to update the header file with the bug fix version. The diff will be large, but we will be kind of updating the third party dep. However, if we plan to make bug fix, it's not a good idea. Best would be to create a fork and make sure its parallel to the upstream, and we can make custom fixes as well. But it then makes additional overhead.

double result;
auto answer = fast_float::from_chars(nptr, nptr + strlen(nptr), result);

if (answer.ec == std::errc())
Copy link
Member

Choose a reason for hiding this comment

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

what is this check doing? shouldn't you just check for null?

Copy link
Author

Choose a reason for hiding this comment

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

fast_float is written in a way where it returns error and we have to handle them explicitly. That's present in their docs.


if (answer.ec == std::errc())
{
if (endptr)
Copy link
Member

Choose a reason for hiding this comment

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

you can move this outside of if block, it is common.


extern "C"
{
double fast_float_strtod(const char *nptr, char **endptr)
Copy link
Member

Choose a reason for hiding this comment

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

@madolson do we always use double type in Redis? Would we never want to use float?

@parthpatel
Copy link
Member

@swaingotnochill I couldn't push changes to your PR, so I created what I was proposing as a draft PR here #1260

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.

3 participants