Skip to content

Commit e291181

Browse files
committed
JSON: add a thread local memory resource ptr
The resource and its heap will be used by a stateless allocator for all parse operations. The heap is initialized at engine shard initialization. Signed-off-by: Abhijat Malviya <[email protected]>
1 parent f0faf6f commit e291181

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/core/json/json_object.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ using namespace std;
1111

1212
namespace dfly {
1313

14+
void InitJSONTLHeap(PMR_NS::memory_resource* mr) {
15+
detail::tl_mr = mr;
16+
}
17+
1418
optional<JsonType> JsonFromString(string_view input, PMR_NS::memory_resource* mr) {
1519
error_code ec;
1620
auto JsonErrorHandler = [](json_errc ec, const ser_context&) {

src/core/json/json_object.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222
namespace dfly {
2323

24+
namespace detail {
25+
26+
inline thread_local PMR_NS::memory_resource* tl_mr = nullptr;
27+
28+
}
29+
30+
void InitJSONTLHeap(PMR_NS::memory_resource* mr);
31+
2432
using JsonType = jsoncons::pmr::json;
2533

2634
// Build a json object from string. If the string is not legal json, will return nullopt

src/server/engine_shard.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ void EngineShard::InitThreadLocal(ProactorBase* pb) {
422422

423423
CompactObj::InitThreadLocal(shard_->memory_resource());
424424
SmallString::InitThreadLocal(data_heap);
425+
InitJSONTLHeap(shard_->memory_resource());
425426

426427
shard_->shard_search_indices_ = std::make_unique<ShardDocIndices>();
427428
}

0 commit comments

Comments
 (0)