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 @@ -28,6 +28,13 @@

//=== Regressions

== {es} version 7.17.23

=== Enhancements

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

== {es} version 7.17.16

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

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

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

Expand Down
9 changes: 9 additions & 0 deletions include/core/CRapidJsonWriterBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ class CRapidJsonWriterBase
return allocator;
}

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

rapidjson::MemoryPoolAllocator<>& getRawAllocator() const {
return this->getAllocator()->get();
}
Expand Down
8 changes: 6 additions & 2 deletions include/core/CScopedRapidJsonPoolAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ class CScopedRapidJsonPoolAllocator {
//! \p allocatorName Unique identifier for the allocator
//! \p jsonOutputWriter JSON output writer that will make use of the allocator
CScopedRapidJsonPoolAllocator(const std::string& allocatorName, T& writer)
: m_Writer(writer) {
: m_Writer(writer), m_AllocatorName(allocatorName) {
m_Writer.pushAllocator(allocatorName);
}

~CScopedRapidJsonPoolAllocator() { m_Writer.popAllocator(); }
~CScopedRapidJsonPoolAllocator() {
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 @@ -825,6 +825,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