aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-12-02 14:26:11 +0100
committerGitHub Enterprise <[email protected]>2024-12-02 14:26:11 +0100
commit9b2fb8069869ec5cea32816a3589d9842595ffea (patch)
tree436a21daef8798377f23765e3f022c92f90ba5ac /src
parentvalidate that root path exists for workspace before adding it (#250) (diff)
downloadzen-9b2fb8069869ec5cea32816a3589d9842595ffea.tar.xz
zen-9b2fb8069869ec5cea32816a3589d9842595ffea.zip
reduce memory churn (#248)
* eliminated allocation in SetCurrentThreadName * reduced memory allocator activity in cache RPC response building * reduced allocations in compact binary building
Diffstat (limited to 'src')
-rw-r--r--src/zencore/compactbinarybuilder.cpp1
-rw-r--r--src/zencore/compactbinarypackage.cpp5
-rw-r--r--src/zencore/include/zencore/compactbinarypackage.h13
-rw-r--r--src/zencore/thread.cpp5
-rw-r--r--src/zenstore/cache/cacherpc.cpp10
5 files changed, 23 insertions, 11 deletions
diff --git a/src/zencore/compactbinarybuilder.cpp b/src/zencore/compactbinarybuilder.cpp
index 3331291ce..a60de023d 100644
--- a/src/zencore/compactbinarybuilder.cpp
+++ b/src/zencore/compactbinarybuilder.cpp
@@ -93,6 +93,7 @@ AppendCompactBinary(const CbFieldView& Value, std::vector<uint8_t>& OutData)
CbWriter::CbWriter()
{
+ States.reserve(4);
States.emplace_back();
}
diff --git a/src/zencore/compactbinarypackage.cpp b/src/zencore/compactbinarypackage.cpp
index 0117b326e..7de161845 100644
--- a/src/zencore/compactbinarypackage.cpp
+++ b/src/zencore/compactbinarypackage.cpp
@@ -308,6 +308,11 @@ CbAttachment::AsObject() const
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+CbPackage::CbPackage()
+{
+ Attachments.reserve(16);
+}
+
void
CbPackage::SetObject(CbObject InObject, const IoHash* InObjectHash, AttachmentResolver* InResolver)
{
diff --git a/src/zencore/include/zencore/compactbinarypackage.h b/src/zencore/include/zencore/compactbinarypackage.h
index fe4a60a30..064481f83 100644
--- a/src/zencore/include/zencore/compactbinarypackage.h
+++ b/src/zencore/include/zencore/compactbinarypackage.h
@@ -172,14 +172,14 @@ public:
using AttachmentResolver = std::function<SharedBuffer(const IoHash& Hash)>;
/** Construct a null package. */
- CbPackage() = default;
+ CbPackage();
/**
* Construct a package from a root object without gathering attachments.
*
* @param InObject The root object, which will be cloned unless it is owned.
*/
- inline explicit CbPackage(CbObject InObject) { SetObject(std::move(InObject)); }
+ inline explicit CbPackage(CbObject InObject) : CbPackage() { SetObject(std::move(InObject)); }
/**
* Construct a package from a root object and gather attachments using the resolver.
@@ -187,7 +187,10 @@ public:
* @param InObject The root object, which will be cloned unless it is owned.
* @param InResolver A function that is invoked for every reference and binary reference field.
*/
- inline explicit CbPackage(CbObject InObject, AttachmentResolver InResolver) { SetObject(std::move(InObject), InResolver); }
+ inline explicit CbPackage(CbObject InObject, AttachmentResolver InResolver) : CbPackage()
+ {
+ SetObject(std::move(InObject), InResolver);
+ }
/**
* Construct a package from a root object without gathering attachments.
@@ -195,7 +198,7 @@ public:
* @param InObject The root object, which will be cloned unless it is owned.
* @param InObjectHash The hash of the object, which must match to avoid validation errors.
*/
- inline explicit CbPackage(CbObject InObject, const IoHash& InObjectHash) { SetObject(std::move(InObject), InObjectHash); }
+ inline explicit CbPackage(CbObject InObject, const IoHash& InObjectHash) : CbPackage() { SetObject(std::move(InObject), InObjectHash); }
/**
* Construct a package from a root object and gather attachments using the resolver.
@@ -204,7 +207,7 @@ public:
* @param InObjectHash The hash of the object, which must match to avoid validation errors.
* @param InResolver A function that is invoked for every reference and binary reference field.
*/
- inline explicit CbPackage(CbObject InObject, const IoHash& InObjectHash, AttachmentResolver InResolver)
+ inline explicit CbPackage(CbObject InObject, const IoHash& InObjectHash, AttachmentResolver InResolver) : CbPackage()
{
SetObject(std::move(InObject), InObjectHash, InResolver);
}
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp
index 78afe924b..ab7e6857a 100644
--- a/src/zencore/thread.cpp
+++ b/src/zencore/thread.cpp
@@ -95,7 +95,10 @@ SetCurrentThreadName([[maybe_unused]] std::string_view ThreadName)
if (SetThreadDescriptionFunc)
{
- SetThreadDescriptionFunc(::GetCurrentThread(), Utf8ToWide(ThreadName).c_str());
+ WideStringBuilder<256> ThreadNameW;
+ Utf8ToWide(ThreadName, ThreadNameW);
+
+ SetThreadDescriptionFunc(::GetCurrentThread(), ThreadNameW.c_str());
}
// The debugger needs to be around to catch the name in the exception. If
diff --git a/src/zenstore/cache/cacherpc.cpp b/src/zenstore/cache/cacherpc.cpp
index 54c2ff7d0..e6b6be525 100644
--- a/src/zenstore/cache/cacherpc.cpp
+++ b/src/zenstore/cache/cacherpc.cpp
@@ -339,7 +339,7 @@ CacheRpcHandler::HandleRpcPutCacheRecords(const CacheRequestContext& Context, co
return CbPackage{};
}
- CbObjectWriter ResponseObject;
+ CbObjectWriter ResponseObject{256};
ResponseObject.BeginArray("Result"sv);
for (bool Value : Results)
{
@@ -768,7 +768,7 @@ CacheRpcHandler::HandleRpcGetCacheRecords(const CacheRequestContext& Context, Cb
{
ZEN_TRACE_CPU("Z$::RpcGetCacheRecords::Response");
CbPackage ResponsePackage;
- CbObjectWriter ResponseObject;
+ CbObjectWriter ResponseObject{2048};
ResponseObject.BeginArray("Result"sv);
for (RecordRequestData& Request : Requests)
@@ -997,7 +997,7 @@ CacheRpcHandler::HandleRpcPutCacheValues(const CacheRequestContext& Context, con
}
{
ZEN_TRACE_CPU("Z$::RpcPutCacheValues::Response");
- CbObjectWriter ResponseObject;
+ CbObjectWriter ResponseObject{1024};
ResponseObject.BeginArray("Result"sv);
for (bool Value : Results)
{
@@ -1213,7 +1213,7 @@ CacheRpcHandler::HandleRpcGetCacheValues(const CacheRequestContext& Context, CbO
{
ZEN_TRACE_CPU("Z$::RpcGetCacheValues::Response");
CbPackage RpcResponse;
- CbObjectWriter ResponseObject;
+ CbObjectWriter ResponseObject{1024};
ResponseObject.BeginArray("Result"sv);
for (const RequestData& Request : Requests)
{
@@ -1731,7 +1731,7 @@ CacheRpcHandler::WriteGetCacheChunksResponse([[maybe_unused]] const CacheRequest
const bool AcceptsPartialChunks = EnumHasAnyFlags(AcceptOptions, RpcAcceptOptions::kAllowPartialCacheChunks);
CbPackage RpcResponse;
- CbObjectWriter Writer;
+ CbObjectWriter Writer{1024};
Writer.BeginArray("Result"sv);
for (ChunkRequest& Request : Requests)