Reconsider / Remove MemoryManager #7127
Replies: 3 comments 5 replies
-
I also tried removing the rpmalloc calls: https://github.com/Veratil/lmms/tree/remove-rpmalloc My general usage test didn't run into any issues, so as a first step stripping out the rpmalloc calls should be fine at least. |
Beta Was this translation helpful? Give feedback.
-
I did some more rigorous profiling by measuring how long it takes LMMS to render this project: Profiling commandsI used this command on both the binary built with rpmalloc, and the binary just using std::alloc: Resultsrpmalloc:
Just std::alloc:
mimalloc:
Given that they're all within a standard deviation of each other, and it's quite a tight spread of results, I think this confirms the hunch that in the real world, the memory allocator being used has a negligible impact on performance. |
Beta Was this translation helpful? Give feedback.
-
Closing as resolved given that |
Beta Was this translation helpful? Give feedback.
-
Motivation / History
Most of LMMS' memory management code has not been touched in quite a number of years, and both C++ and computer hardware itself have changed enough since then that I think it needs a thorough second look.
I'm going to focus on the MemoryManager class in this discussion, and leave memory pools, etc. aside.
Here's the original mailing list discussion of the MemoryManager, back when it was implemented by Vesa in #1088. It pre-allocated a big chunk of memory on application launch, which was then given to classes initialized with the
MM_OPERATORS
macro. #3873 replaced that poorly performant custom implementation with rpmalloc, and completely removed the pre-allocation.Since that time, standard library implementations of allocators have become better optimized, and hardware has moved to 64-bit systems with more available memory, which makes fragmentation far less of a concern than it used to be.
lukas-w has an open PR to refactor memory management (#4443), which is in need of a rebase and mostly focuses on memory pools, as far as I can tell.
Alternative memory manager
I tested out mimalloc as a potential alternative, as it seems to consistently outperform other memory allocators (source). The relatively minor changes necessary to do so can be tested out from my branch: https://github.com/TechnoPorg/lmms/tree/mimalloc-memory-allocator. Note that you will need the mimalloc package installed locally (mimalloc-devel on Fedora).
Here are some basic test results I got using an admittedly unimpressive benchmark (run on Linux, target DEBUG, clang):
These results varied pretty widely and I by no means did them in a controlled environment, so take them with a grain of salt. The mimalloc time seemed to vary the most, and was often equal to or occasionally even slightly underperforming the default allocator. What was consistent, though, is that rpmalloc performed the worst.
I did not test the total amount of memory used.
Suggestions
Personally, I think that getting rid of the custom memory manager operators entirely is the best course of action. Imho reliance on standard C++ behaviour is always the safest course of action, and using default memory management will simplify LMMS code in terms of readability and maintenance. It should also increase performance slightly over rpmalloc.
We could also investigate using mimalloc as a drop-in replacement for rpmalloc, but unless someone else can conclusively show that it's markedly better, I would say an extra dependency and the responsibility of maintaining our own memory manager are not worth a very inconsistent 2.3% improvement.
Beta Was this translation helpful? Give feedback.
All reactions