diff options
| author | Stefan Boberg <[email protected]> | 2024-12-02 14:26:11 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-12-02 14:26:11 +0100 |
| commit | 9b2fb8069869ec5cea32816a3589d9842595ffea (patch) | |
| tree | 436a21daef8798377f23765e3f022c92f90ba5ac /src/zencore | |
| parent | validate that root path exists for workspace before adding it (#250) (diff) | |
| download | zen-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/zencore')
| -rw-r--r-- | src/zencore/compactbinarybuilder.cpp | 1 | ||||
| -rw-r--r-- | src/zencore/compactbinarypackage.cpp | 5 | ||||
| -rw-r--r-- | src/zencore/include/zencore/compactbinarypackage.h | 13 | ||||
| -rw-r--r-- | src/zencore/thread.cpp | 5 |
4 files changed, 18 insertions, 6 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 |