Commit b00cd15d authored by John Esmet's avatar John Esmet

FT-282 Optimize key comparisons by adding an unlikely clause to

toku_dbt_is_infinite(). Also, check for the builtin key comparison
function to get an inlined version to run when possible.
parent 1cda4774
...@@ -97,6 +97,9 @@ PATENT RIGHTS GRANT: ...@@ -97,6 +97,9 @@ PATENT RIGHTS GRANT:
#include <ft/fttypes.h> #include <ft/fttypes.h>
#include <portability/memory.h> #include <portability/memory.h>
// TODO: this should really all be encapsulated in ft/comparator.cc
int toku_builtin_compare_fun(DB *, const DBT *a, const DBT *b) __attribute__((__visibility__("default")));
namespace toku { namespace toku {
// a comparator object encapsulates the data necessary for // a comparator object encapsulates the data necessary for
...@@ -109,6 +112,7 @@ namespace toku { ...@@ -109,6 +112,7 @@ namespace toku {
_cmp = cmp; _cmp = cmp;
XCALLOC(_fake_db); XCALLOC(_fake_db);
_fake_db->cmp_descriptor = desc; _fake_db->cmp_descriptor = desc;
_builtin = _cmp == &toku_builtin_compare_fun;
} }
void destroy() { void destroy() {
...@@ -132,9 +136,10 @@ namespace toku { ...@@ -132,9 +136,10 @@ namespace toku {
} }
int operator()(const DBT *a, const DBT *b) const { int operator()(const DBT *a, const DBT *b) const {
// TODO: add an unlikely() compiler note for this branch if (__builtin_expect(!!(toku_dbt_is_infinite(a) || toku_dbt_is_infinite(b)), 0)) {
if (toku_dbt_is_infinite(a) || toku_dbt_is_infinite(b)) {
return toku_dbt_infinite_compare(a, b); return toku_dbt_infinite_compare(a, b);
} else if (_builtin) {
return toku_builtin_compare_fun(nullptr, a, b);
} else { } else {
// yikes, const sadness here // yikes, const sadness here
return _cmp(const_cast<DB *>(_fake_db), a, b); return _cmp(const_cast<DB *>(_fake_db), a, b);
...@@ -144,6 +149,7 @@ namespace toku { ...@@ -144,6 +149,7 @@ namespace toku {
private: private:
DB *_fake_db; DB *_fake_db;
ft_compare_func _cmp; ft_compare_func _cmp;
bool _builtin;
}; };
} /* namespace toku */ } /* namespace toku */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment