From e288430c05359706bcb0f78730af2997ab0db07f Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Tue, 8 Sep 2020 15:51:20 +0300 Subject: 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. --- src/config.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/config.h') 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__ -- cgit v1.2.1