File tree Expand file tree Collapse file tree 5 files changed +14
-3
lines changed Expand file tree Collapse file tree 5 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -790,8 +790,8 @@ void CompactObj::SetString(std::string_view str) {
790
790
}
791
791
}
792
792
793
- if (kUseSmallStrings ) {
794
- if (( taglen_ == 0 && encoded. size () < ( 1 << 13 )) ) {
793
+ if (kUseSmallStrings && SmallString::CanAllocate (encoded. size ()) ) {
794
+ if (taglen_ == 0 ) {
795
795
SetMeta (SMALL_TAG, mask);
796
796
tl.small_str_bytes += u_.small_str .Assign (encoded);
797
797
return ;
Original file line number Diff line number Diff line change @@ -25,4 +25,8 @@ void SegmentAllocator::ValidateMapSize() {
25
25
}
26
26
}
27
27
28
+ bool SegmentAllocator::CanAllocate () {
29
+ return address_table_.size () < (1u << kSegmentIdBits );
30
+ }
31
+
28
32
} // namespace dfly
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ class SegmentAllocator {
30
30
using Ptr = uint32_t ;
31
31
32
32
SegmentAllocator (mi_heap_t * heap);
33
+ bool CanAllocate ();
33
34
34
35
uint8_t * Translate (Ptr p) const {
35
36
return address_table_[p & kSegmentIdMask ] + Offset (p);
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ void SmallString::InitThreadLocal(void* heap) {
45
45
XXH3_64bits_reset_withSeed (tl.xxh_state .get (), kHashSeed );
46
46
}
47
47
48
+ bool SmallString::CanAllocate (size_t size) {
49
+ return size <= kMaxSize && tl.seg_alloc ->CanAllocate ();
50
+ }
51
+
48
52
size_t SmallString::UsedThreadLocal () {
49
53
return tl.seg_alloc ? tl.seg_alloc ->used () : 0 ;
50
54
}
Original file line number Diff line number Diff line change 10
10
11
11
namespace dfly {
12
12
13
- // blob strings of upto ~64KB . Small sizes are probably predominant
13
+ // blob strings of upto ~256B . Small sizes are probably predominant
14
14
// for in-memory workloads, especially for keys.
15
15
// Please note that this class does not have automatic constructors and destructors, therefore
16
16
// it requires explicit management.
17
17
class SmallString {
18
18
static constexpr unsigned kPrefLen = 10 ;
19
+ static constexpr unsigned kMaxSize = (1 << 8 ) - 1 ;
19
20
20
21
public:
21
22
static void InitThreadLocal (void * heap);
22
23
static size_t UsedThreadLocal ();
24
+ static bool CanAllocate (size_t size);
23
25
24
26
void Reset () {
25
27
size_ = 0 ;
You can’t perform that action at this time.
0 commit comments