Aggressive inlining

This commit is contained in:
Junhyun Shim 2022-04-21 02:44:19 +02:00
parent 3f9f781226
commit 7304c337f8
2 changed files with 12 additions and 20 deletions

View File

@ -25,6 +25,7 @@
#include <cassert>
#include <string_view>
#include "logger.hpp"
#include "macro.hpp"
extern thread_local mako::Logger logr;
@ -33,7 +34,7 @@ namespace mako {
enum class FutureRC { OK, RETRY, CONFLICT, ABORT };
template <class FutureType>
FutureRC handleForOnError(fdb::Transaction tx, FutureType f, std::string_view step) {
force_inline FutureRC handleForOnError(fdb::Transaction& tx, FutureType& f, std::string_view step) {
if (auto err = f.error()) {
if (err.is(1020 /*not_committed*/)) {
return FutureRC::CONFLICT;
@ -51,7 +52,7 @@ FutureRC handleForOnError(fdb::Transaction tx, FutureType f, std::string_view st
}
template <class FutureType>
FutureRC waitAndHandleForOnError(fdb::Transaction tx, FutureType f, std::string_view step) {
force_inline FutureRC waitAndHandleForOnError(fdb::Transaction& tx, FutureType& f, std::string_view step) {
assert(f);
if (auto err = f.blockUntilReady()) {
logr.error("'{}' found while waiting for on_error() future, step: {}", err.what(), step);
@ -62,7 +63,7 @@ FutureRC waitAndHandleForOnError(fdb::Transaction tx, FutureType f, std::string_
// wait on any non-immediate tx-related step to complete. Follow up with on_error().
template <class FutureType>
FutureRC waitAndHandleError(fdb::Transaction tx, FutureType f, std::string_view step) {
force_inline FutureRC waitAndHandleError(fdb::Transaction& tx, FutureType& f, std::string_view step) {
assert(f);
auto err = fdb::Error{};
if ((err = f.blockUntilReady())) {

View File

@ -55,25 +55,13 @@ force_inline int intSize(std::string_view sv) {
/* random string */
template <typename Char>
void randomString(Char* str, int len) {
force_inline void randomString(Char* str, int len) {
assert(len >= 0);
for (auto i = 0; i < len; i++) {
str[i] = ('!' + urand(0, 'z' - '!')); /* generate a char from '!' to 'z' */
}
}
/* random numeric string */
template <bool Clear = true, typename Char>
void randomNumericString(std::basic_string<Char>& str, int len) {
if constexpr (Clear)
str.clear();
assert(len >= 0);
str.reserve(str.size() + static_cast<size_t>(len));
for (auto i = 0; i < len; i++) {
str.push_back('0' + urand(0, 9)); /* generage a char from '0' to '9' */
}
}
/* given the total number of rows to be inserted,
* the worker process index p_idx and the thread index t_idx (both 0-based),
* and the total number of processes, total_p, and threads, total_t,
@ -109,12 +97,12 @@ int digits(int num);
/* fill memory slice [str, str + len) as stringified, zero-padded num */
template <typename Char>
void numericWithFill(Char* str, int len, int num) {
force_inline void numericWithFill(Char* str, int len, int num) {
static_assert(sizeof(Char) == 1);
assert(num >= 0);
for (auto i = len - 1; i >= 0; i--) {
memset(str, '0', len);
for (auto i = len - 1; num > 0 && i >= 0; i--, num /= 10) {
str[i] = (num % 10) + '0';
num /= 10;
}
}
@ -132,7 +120,10 @@ void genKey(Char* str, std::string_view prefix, Arguments const& args, int num)
}
template <typename Char>
void prepareKeys(int op, std::basic_string<Char>& key1, std::basic_string<Char>& key2, Arguments const& args) {
force_inline void prepareKeys(int op,
std::basic_string<Char>& key1,
std::basic_string<Char>& key2,
Arguments const& args) {
const auto key1_num = nextKey(args);
genKey(key1.data(), KEY_PREFIX, args, key1_num);
if (args.txnspec.ops[op][OP_RANGE] > 0) {