Skip to content

replace fast_float (C++) with ffc#3329

Merged
zuiderkwast merged 12 commits into
valkey-io:unstablefrom
lemire:ffh
Mar 11, 2026
Merged

replace fast_float (C++) with ffc#3329
zuiderkwast merged 12 commits into
valkey-io:unstablefrom
lemire:ffh

Conversation

@lemire

@lemire lemire commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

There is now a port of fast_float in C. So instead of having an optional fast_float dependency, we can just use ffc instead, unconditionally.

https://github.com/kolemannix/ffc.h

It is a high quality port by @kolemannix. The performance should be the same or improved.

The PR is quite simple and should not be controversial.

Note : I am the maintainer and main author of fast_float.

@dvkashapov dvkashapov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The build fails currently because there is no ffc itself? Do you suggest we devendor this dependency and expect user to have it installed on the system? I just took a glance at the code, did not do a proper review.

    LINK valkey-benchmark
/usr/bin/ld: cannot find ../deps/fast_float_c_interface/fast_float_strtod.o: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:727: valkey-benchmark] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/dvkashapov/ff/src'
make: *** [Makefile:6: all] Error 2

@zuiderkwast

Copy link
Copy Markdown
Contributor

Hi @lemire, nice to see you here. Do you think ffc is mature enough already? I see it has a lot of activity in the last days. I hope we can avoid updating it too often.

Please also add ffc.h so the code compiles. :)

@kolemannix

Copy link
Copy Markdown

Do you think ffc is mature enough already? I see it has a lot of activity in the last days.

It's a fair question; all of the activity since the first release has been around project management, establishing a versioning scheme, ci, tooling on the repo itself. We have made only one true code change since release, which was not a correctness fix.

The logic itself is of course very mature as it comes from fast_float and the port is direct. The question is around the accuracy of the port, but with all of the fast_float test suite passing, it seems unlikely there is any major miss.

I see the existing fast_float usage is already opt-in in valkey, that could be a good way to 'let it soak' for a little while before making it the default.

@zuiderkwast

Copy link
Copy Markdown
Contributor

I see the existing fast_float usage is already opt-in in valkey, that could be a good way to 'let it soak' for a little while before making it the default.

Maybe it's not necessary. Now that we have a plain C solution, and we've had fast float for a year as opt-in, it seems safe to me to use ffc now without a fallback. Let's see what others think.

We made fast float opt-in just because it's C++ and we didn't want to change the toolchain requirements, but otherwise we want to avoid compile-time options. We want a uniform build and many users run on containers or other pre-built binaries and/or are not able to decide how it's compiled.

@lemire

lemire commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

@dvkashapov

Yes, I think this can be vendored. I simply forgot to check in the file, which I just did now.

Please also add ffc.h so the code compiles. :)

Yeah. Sorry about that.

I see the existing fast_float usage is already opt-in in valkey, that could be a good way to 'let it soak' for a little while before making it the default. Do you think ffc is mature enough already?

I am quite happy that valkey depends on the library that I maintain (fast_float). It is indeed correct that fast_float is more mature. But yeah, I have confidence in ffc. It is up to the valkey folks to decide. (And, of course, to consider @kolemannix's opinion on the matter.)

Maybe some background is in order. Antirez raised a bit of attention when he announced that he had used AI to port fast_float to C so that redis would not need a C++ compiler at compile time. Seemed reasonable. Yet I personally do not think that the vibe coded 'C port' is good. Meanwhile, independently, @kolemannix did an actual port of fast_float. His port is not vibe coded. So there is discussion in the redis repo about adopting ffh, and so forth. It felt to me that valkey should have the same option.

@madolson madolson added the major-decision-approved Major decision approved by TSC team label Mar 9, 2026
@madolson

madolson commented Mar 9, 2026

Copy link
Copy Markdown
Member

If we can review this in the next day or so, we can merge this before 9.1 cutoff. This seems worth pulling in.

@madolson madolson moved this to Needs Review in Valkey 9.1 Mar 9, 2026
@codecov

codecov Bot commented Mar 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.44%. Comparing base (fc217fc) to head (5ddb25f).
⚠️ Report is 15 commits behind head on unstable.

Files with missing lines Patch % Lines
src/valkey_strtod.c 57.14% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3329      +/-   ##
============================================
- Coverage     75.05%   74.44%   -0.62%     
============================================
  Files           129      130       +1     
  Lines         71553    72553    +1000     
============================================
+ Hits          53705    54011     +306     
- Misses        17848    18542     +694     
Files with missing lines Coverage Δ
deps/fast_float/ffc.h 27.36% <ø> (ø)
src/debug.c 54.83% <100.00%> (ø)
src/resp_parser.c 98.43% <100.00%> (-0.04%) ⬇️
src/sort.c 96.46% <100.00%> (ø)
src/t_zset.c 97.07% <100.00%> (ø)
src/util.c 67.57% <100.00%> (+0.38%) ⬆️
src/valkey_strtod.c 57.14% <57.14%> (ø)

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sarthakaggarwal97

sarthakaggarwal97 commented Mar 9, 2026

Copy link
Copy Markdown
Contributor
util.c:(.text+0x29e1): undefined reference to `fast_float_strtod_n'

quick note - CI is failing because CMake is not updated to build/link the new fast_float_c_interface.

@lemire

lemire commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

@sarthakaggarwal97 Let me have a look

@lemire

lemire commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

Verified locally, I had not tested CMake. I will fix in a minute or so.

lemire added 5 commits March 9, 2026 14:52
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>

@zuiderkwast zuiderkwast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Thank you!

We wouldn't really need the fast_float_c_interface wrapper anymore. We added it for fast float to distinguish the C++ code that we built with different compiler options and linked it as a lib. With C we could just include ffc.h in e.g. src/util.c. It'd be slightly simpler, but doesn't matter much. We can also just keep it as-is.

@kolemannix

Copy link
Copy Markdown

@lemire Would you like to remove the extra build step and wrapper interface? I think its worth it, as the aim is toolchain complexity reduction!

I could take a crack as well.

Signed-off-by: Daniel Lemire <daniel@lemire.me>
@lemire

lemire commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

I did the simplification. It does not simplify a whole lot: you basically move the definitions from the deps directory to the src directory. It is probably more or less even in terms of lines of code.

BUT you do get right of an extra directory in deps, which is nice.

@zuiderkwast zuiderkwast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did the simplification. It does not simplify a whole lot: you basically move the definitions from the deps directory to the src directory. It is probably more or less even in terms of lines of code.

BUT you do get right of an extra directory in deps, which is nice.

I think it's worth it. We got rid of an extra Makefile and a CMakeLists.txt and we don't need to link it as a separate library anymore. Your last commit has good numbers:

+83 -111 lines changed

Thanks for taking the time!

@sarthakaggarwal97 sarthakaggarwal97 added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Mar 10, 2026
lemire added 2 commits March 10, 2026 12:43
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
lemire added 2 commits March 10, 2026 13:09
Signed-off-by: Daniel Lemire <daniel@lemire.me>
Signed-off-by: Daniel Lemire <daniel@lemire.me>
@lemire

lemire commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

@zuiderkwast I trimmed some more fat.

@zuiderkwast zuiderkwast merged commit 6414720 into valkey-io:unstable Mar 11, 2026
66 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in Valkey 9.1 Mar 11, 2026
@zuiderkwast zuiderkwast added the release-notes This issue should get a line item in the release notes label Mar 11, 2026
madolson added a commit to madolson/valkey that referenced this pull request Mar 15, 2026
- Fix release date to Mon Mar 18 2026
- Fix typos: duplicate 'load', 'keyes' -> 'keys', duplicate 'INFO'
- Remove reverted contributor (arshidkv12, valkey-io#3137)
- Add 7 new release-notes entries from upstream/unstable merge:
  CLUSTERSCAN (valkey-io#2934), MSETEX (valkey-io#3121), availability-zone (valkey-io#3156),
  stream range optimization (valkey-io#3002), RDB as AOF preamble (valkey-io#1901),
  unsigned 64-bit module config (valkey-io#1546), fast_float -> ffc (valkey-io#3329)

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
JimB123 pushed a commit that referenced this pull request Mar 19, 2026
There is now a port of fast_float in C. So instead of having an optional
fast_float dependency, we can just use ffc instead, unconditionally.

https://github.com/kolemannix/ffc.h

It is a high quality port. The performance should be the same or
improved.

Note : I am the maintainer and main author of fast_float.

---------

Signed-off-by: Daniel Lemire <daniel@lemire.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major-decision-approved Major decision approved by TSC team release-notes This issue should get a line item in the release notes run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants