Hi I see that SQLite has many small optimizations being checked-in. Wouldn't it help to use the following macros and use unlikely(...) for error paths:
#ifdef __GNUC__ #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) #else #define likely(x) (x) #define unlikely(x) (x) #endif It helps for branch prediction and instruction cache hits as cold branches are moved away from hot branches. CPU have branch predictor, but for complex code, with many 'if', static hints can still helps. Better is to compile with PGO (profile guided optimization), but few people use PGO in practice. Doing a Google search, I found that __builtin_expect was disabled because it did not work with old gcc and was then completely removed in 2012: http://dev.gitblit.com:8080/cgi-bin/repo/sqlite/info/e01f9ed9450d3e23 http://sqlite.org/src4/info/d618b9b1069e66779c298798acb24044664b5109 However, it's possible to check fo gcc version using something like this as found here: http://www.opensource.apple.com/source/X11proto/X11proto-57/xproto/xproto-7.0.21/Xfuncproto.h.in?txt #if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303) # define _X_LIKELY(x) __builtin_expect(!!(x), 1) # define _X_UNLIKELY(x) __builtin_expect(!!(x), 0) #else /* not gcc >= 3.3 */ # define _X_LIKELY(x) (x) # define _X_UNLIKELY(x) (x) #endif I'm curious about the outcome on SQLite benchmarks. Regards Dominique