Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@

* Fix "stack use after scope" memory error. (See {ml-pull}2673[#2673].)

== {es} version 8.14.1

=== Enhancements

* Improve memory allocation management for JSON processing to reduce memory usage.
(See {ml-pull}2679[#2679].)

== {es} version 8.14.0

=== Bug Fixes
Expand Down
3 changes: 3 additions & 0 deletions include/api/CJsonOutputWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class API_EXPORT CJsonOutputWriter {
//! \p allocatorName A unique identifier for the allocator
void pushAllocator(const std::string& allocatorName);

//! remove allocator from cache
void removeAllocator(const std::string& allocatorName);

//! revert to using the previous allocator for JSON output processing
void popAllocator();

Expand Down
11 changes: 8 additions & 3 deletions include/core/CBoostJsonWriterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
#include <boost/unordered_set.hpp>

#include <cmath>
#include <iomanip>
#include <iostream>
#include <memory>
#include <regex>
#include <stack>

namespace json = boost::json;
Expand Down Expand Up @@ -134,6 +131,14 @@ class CBoostJsonWriterBase {
return this->getAllocator()->get();
}

void removeAllocator(const std::string& allocatorName) {
auto allocator = m_AllocatorCache.find(allocatorName);
if (allocator != m_AllocatorCache.end()) {
allocator->second.reset();
m_AllocatorCache.erase(allocator);
}
}

bool isComplete() const {
bool ret = m_Levels.empty() || m_Levels.top() == 0;
return ret;
Expand Down
9 changes: 7 additions & 2 deletions include/core/CScopedBoostJsonPoolAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define INCLUDED_ml_core_CScopedBoostJsonPoolAllocator_h

#include <boost/json.hpp>
#include <string>

namespace ml {
namespace core {
Expand All @@ -31,14 +32,18 @@ class CScopedBoostJsonPoolAllocator {
//! \p allocatorName Unique identifier for the allocator
//! \p jsonOutputWriter JSON output writer that will make use of the allocator
CScopedBoostJsonPoolAllocator(const std::string& allocatorName, T& writer)
: m_Writer(writer) {
: m_Writer(writer), m_AllocatorName(allocatorName) {
m_Writer.pushAllocator(allocatorName);
}

~CScopedBoostJsonPoolAllocator() { m_Writer.popAllocator(); }
~CScopedBoostJsonPoolAllocator() {
m_Writer.popAllocator();
m_Writer.removeAllocator(m_AllocatorName);
}

private:
T& m_Writer;
std::string m_AllocatorName;
};
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/api/CJsonOutputWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ void CJsonOutputWriter::pushAllocator(const std::string& allocatorName) {
m_Writer.pushAllocator(allocatorName);
}

void CJsonOutputWriter::removeAllocator(const std::string& allocatorName) {
m_Writer.removeAllocator(allocatorName);
}

void CJsonOutputWriter::popAllocator() {
m_Writer.popAllocator();
}
Expand Down