mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
refactor: optimize NodeStore object conversion: (#4353)
When writing objects to the NodeStore, we need to convert them from the in-memory format to the binary format used by the node store. The conversion is handled by the `EncodedBlob` class, which is only instantiated on the stack. Coupled with the fact that most objects are under 1024 bytes in size, this presents an opportunity to elide a memory allocation in a critical path. This commit also simplifies the interface of `EncodedBlob` and eliminates a subtle corner case that could result in dangling pointers. These changes are not expected to cause a significant reduction in memory usage. The change avoids the use of a `std::shared_ptr` when unnecessary and tries to use stack-based memory allocation instead of the heap whenever possible. This is a net gain both in terms of memory usage (lower fragmentation) and performance (less work to do at runtime).
This commit is contained in:
@@ -56,10 +56,9 @@ public:
|
||||
|
||||
auto batch = createPredictableBatch(numObjectsToTest, seedValue);
|
||||
|
||||
EncodedBlob encoded;
|
||||
for (int i = 0; i < batch.size(); ++i)
|
||||
{
|
||||
encoded.prepare(batch[i]);
|
||||
EncodedBlob encoded(batch[i]);
|
||||
|
||||
DecodedBlob decoded(
|
||||
encoded.getKey(), encoded.getData(), encoded.getSize());
|
||||
|
||||
Reference in New Issue
Block a user