Optimize ascii_pack in debug mode
This commit is contained in:
parent
d5281721bd
commit
81ffb189ef
2
helio
2
helio
|
@ -1 +1 @@
|
||||||
Subproject commit 2a6629d7e47da545bede22507d04bd2de409b1cb
|
Subproject commit 408d201f365ce886f1b1e762810e81e0509ea8b9
|
|
@ -208,7 +208,7 @@ constexpr bool kUseSmallStrings = true;
|
||||||
|
|
||||||
/// TODO: Ascii encoding becomes slow for large blobs. We should factor it out into a separate
|
/// TODO: Ascii encoding becomes slow for large blobs. We should factor it out into a separate
|
||||||
/// file and implement with SIMD instructions.
|
/// file and implement with SIMD instructions.
|
||||||
constexpr bool kUseAsciiEncoding = false;
|
constexpr bool kUseAsciiEncoding = true;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -393,6 +393,9 @@ quicklist* RobjWrapper::GetQL() const {
|
||||||
return (quicklist*)inner_obj_;
|
return (quicklist*)inner_obj_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC push_options
|
||||||
|
#pragma GCC optimize("Ofast")
|
||||||
|
|
||||||
// len must be at least 16
|
// len must be at least 16
|
||||||
void ascii_pack(const char* ascii, size_t len, uint8_t* bin) {
|
void ascii_pack(const char* ascii, size_t len, uint8_t* bin) {
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
@ -420,17 +423,14 @@ void ascii_unpack(const uint8_t* bin, size_t ascii_len, char* ascii) {
|
||||||
uint8_t p = 0;
|
uint8_t p = 0;
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
|
||||||
auto step = [&] {
|
|
||||||
uint8_t src = *bin; // keep on stack in case we unpack inplace.
|
|
||||||
*ascii++ = (p >> (8 - i)) | ((src << i) & kM);
|
|
||||||
p = src;
|
|
||||||
++bin;
|
|
||||||
};
|
|
||||||
|
|
||||||
while (ascii_len >= 8) {
|
while (ascii_len >= 8) {
|
||||||
for (i = 0; i < 7; ++i) {
|
for (i = 0; i < 7; ++i) {
|
||||||
step();
|
uint8_t src = *bin; // keep on stack in case we unpack inplace.
|
||||||
|
*ascii++ = (p >> (8 - i)) | ((src << i) & kM);
|
||||||
|
p = src;
|
||||||
|
++bin;
|
||||||
}
|
}
|
||||||
|
|
||||||
ascii_len -= 8;
|
ascii_len -= 8;
|
||||||
*ascii++ = p >> 1;
|
*ascii++ = p >> 1;
|
||||||
}
|
}
|
||||||
|
@ -443,6 +443,8 @@ void ascii_unpack(const uint8_t* bin, size_t ascii_len, char* ascii) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC pop_options
|
||||||
|
|
||||||
// compares packed and unpacked strings. packed must be of length = binpacked_len(ascii_len).
|
// compares packed and unpacked strings. packed must be of length = binpacked_len(ascii_len).
|
||||||
bool compare_packed(const uint8_t* packed, const char* ascii, size_t ascii_len) {
|
bool compare_packed(const uint8_t* packed, const char* ascii, size_t ascii_len) {
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
@ -811,7 +813,7 @@ bool CompactObj::HasAllocated() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompactObj::GetString(string* res) const {
|
void __attribute__((noinline)) CompactObj::GetString(string* res) const {
|
||||||
string_view slice = GetSlice(res);
|
string_view slice = GetSlice(res);
|
||||||
if (res->data() != slice.data()) {
|
if (res->data() != slice.data()) {
|
||||||
res->assign(slice);
|
res->assign(slice);
|
||||||
|
|
|
@ -327,8 +327,8 @@ TEST_F(DflyEngineTest, Memcache) {
|
||||||
|
|
||||||
TEST_F(DflyEngineTest, LimitMemory) {
|
TEST_F(DflyEngineTest, LimitMemory) {
|
||||||
mi_option_enable(mi_option_limit_os_alloc);
|
mi_option_enable(mi_option_limit_os_alloc);
|
||||||
string blob(1 << 15, 'a');
|
string blob(128, 'a');
|
||||||
for (size_t i = 0; i < 1000; ++i) {
|
for (size_t i = 0; i < 10000; ++i) {
|
||||||
auto resp = Run({"set", absl::StrCat(blob, i), blob});
|
auto resp = Run({"set", absl::StrCat(blob, i), blob});
|
||||||
ASSERT_THAT(resp, RespEq("OK"));
|
ASSERT_THAT(resp, RespEq("OK"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue