-
Notifications
You must be signed in to change notification settings - Fork 65
[ML] Clearing JSON memory allocators #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Use scoped JSON memory allocators to avoid excessive memory accumulation where-ever the JSON output writer is persisted. Fixes #26
lib/api/CJsonOutputWriter.cc
Outdated
@@ -430,6 +431,10 @@ const CJsonOutputWriter::TStrVec &CJsonOutputWriter::fieldNames(void) const | |||
bool CJsonOutputWriter::writeRow(const TStrStrUMap &dataRowFields, | |||
const TStrStrUMap &overrideDataRowFields) | |||
{ | |||
typedef core::CScopedRapidJsonPoolAllocator<core::CRapidJsonConcurrentLineWriter> TScopedAllocator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per #32, can we switch to using TScopedAllocator = ...
here and throughout.
Otherwise, this is LGTM. The two questions I have are:
|
Replacing typedef declarations with 'using' instead.
Thanks for the review comments @tveasey. The extra Json documents in use in CForecastDataSink came in to existence when I refactored the Json output writer and memory allocator. The scoped memory allocator is cached, it does not actually get destroyed at end of scope. Rather, it simply calls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for clarifying! LGTM.
Added comments to CRapidJsonWriterBase to clarify the intent and purpose of the allocator stack and the interaction with CScopedRapidJsonPoolAllocator
include/core/CRapidJsonWriterBase.h
Outdated
// for the writer at nested scope. | ||
// | ||
// Note that allocators are not destroyed by the pop operation, they persist for the lifetime of the | ||
// writer in a cache for swift retrieval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use //!
comments so that this is included in the Doxygen output.
include/core/CRapidJsonWriterBase.h
Outdated
@@ -100,6 +100,18 @@ class CRapidJsonWriterBase : public JSON_WRITER<OUTPUT_STREAM, SOURCE_ENCODING, | |||
public: | |||
using TRapidJsonWriterBase = JSON_WRITER<OUTPUT_STREAM, SOURCE_ENCODING, TARGET_ENCODING, STACK_ALLOCATOR, WRITE_FLAGS>; | |||
|
|||
// Instances of this class may very well be long lived, potentially for the lifetime of the application. | |||
// Over the course of that lifetimme resources will accumulate in the underlying rapidjson memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lifetimme |-> lifetime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I tested it and can not reproduce #26 with this fix. |
Use scoped JSON memory allocators to avoid excessive memory accumulation where-ever the JSON output writer is persisted. Fixes #26
Use scoped JSON memory allocators to avoid excessive memory accumulation where-ever the JSON output writer is persisted. Fixes #26
[ML] Clearing JSON memory allocators Use scoped JSON memory allocators to avoid excessive memory accumulation where-ever the JSON output writer is persisted. Fixes #26
Use scoped JSON memory allocators to avoid excessive memory accumulation
where-ever the JSON output writer is persisted.
Fixes #26