diff options
author | filipe oliveira <filipecosta.90@gmail.com> | 2022-10-15 10:17:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-15 12:17:41 +0300 |
commit | 29380ff77d5da51d3065b810a9f93171f8724c1a (patch) | |
tree | d40fb96981280f3dd5ddea2833997cfc88d28b35 /src/Makefile | |
parent | 9ab873d9d35e789a228c5281d57c9c4fdc1e4ce1 (diff) | |
download | redis-29380ff77d5da51d3065b810a9f93171f8724c1a.tar.gz |
optimizing d2string() and addReplyDouble() with grisu2: double to string conversion based on Florian Loitsch's Grisu-algorithm (#10587)
All commands / use cases that heavily rely on double to a string representation conversion,
(e.g. meaning take a double-precision floating-point number like 1.5 and return a string like "1.5" ),
could benefit from a performance boost by swapping snprintf(buf,len,"%.17g",value) by the
equivalent [fpconv_dtoa](https://github.com/night-shift/fpconv) or any other algorithm that ensures
100% coverage of conversion.
This is a well-studied topic and Projects like MongoDB. RedPanda, PyTorch leverage libraries
( fmtlib ) that use the optimized double to string conversion underneath.
The positive impact can be substantial. This PR uses the grisu2 approach ( grisu explained on
https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf section 5 ).
test suite changes:
Despite being compatible, in some cases it produces a different result from printf, and some tests
had to be adjusted.
one case is that `%.17g` (which means %e or %f which ever is shorter), chose to use `5000000000`
instead of 5e+9, which sounds like a bug?
In other cases, we changed TCL to compare numbers instead of strings to ignore minor rounding
issues (`expr 0.8 == 0.79999999999999999`)
Diffstat (limited to 'src/Makefile')
-rw-r--r-- | src/Makefile | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile index 2ffddef1b..7e17f1f83 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ ifeq ($(OPTIMIZATION),-O3) REDIS_CFLAGS+=-flto REDIS_LDFLAGS+=-flto endif -DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram +DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram fpconv NODEPS:=clean distclean # Default settings @@ -229,7 +229,7 @@ ifdef OPENSSL_PREFIX endif # Include paths to dependencies -FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram +FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -I../deps/fpconv # Determine systemd support and/or build preference (defaulting to auto-detection) BUILD_WITH_SYSTEMD=no @@ -395,7 +395,7 @@ endif # redis-server $(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) - $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a $(FINAL_LIBS) + $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS) # redis-sentinel $(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME) |