summaryrefslogtreecommitdiff
path: root/src/config.h
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2020-09-08 15:51:20 +0300
committerOran Agra <oran@redislabs.com>2020-12-06 14:54:34 +0200
commite288430c05359706bcb0f78730af2997ab0db07f (patch)
treef164e852d7661ddfa50b0ff660a08d44cd4ef4f4 /src/config.h
parent7ca00d694d44be13a3ff9ff1c96b49222ac9463b (diff)
downloadredis-e288430c05359706bcb0f78730af2997ab0db07f.tar.gz
Sanitize dump payload: performance optimizations and tuning
First, if the ziplist header is surely inside the ziplist, do fast path decoding rather than the careful one. In that case, streamline the encoding if-else chain to be executed only once, and the encoding validity tested at the end. encourage inlining likely / unlikely hints for speculative execution Assertion used _exit(1) to tell the compiler that the code after them is not reachable and get rid of warnings. But in some cases assertions are placed inside tight loops, and any piece of code in them can slow down execution (code cache and other reasons), instead using either abort() or better yet, unreachable builtin.
Diffstat (limited to 'src/config.h')
-rw-r--r--src/config.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h
index 2cd44f927..b8723e7ce 100644
--- a/src/config.h
+++ b/src/config.h
@@ -97,6 +97,20 @@
#define redis_fsync fsync
#endif
+#if __GNUC__ >= 4
+#define redis_unreachable __builtin_unreachable
+#else
+#define redis_unreachable abort
+#endif
+
+#if __GNUC__ >= 3
+#define likely(x) __builtin_expect(!!(x), 1)
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#else
+#define likely(x) (x)
+#define unlikely(x) (x)
+#endif
+
/* Define rdb_fsync_range to sync_file_range() on Linux, otherwise we use
* the plain fsync() call. */
#ifdef __linux__