From an interesting discussion at [Archive.is/WayBack] FaceBook: Delphi developer thread by Jarto Tarpio with some measurements by Jarto Tarpio and André Mussche.
- Manipulation of strings and lists in Delphi have high memory allocation/deallocation rates, so HTTP related services with high call rates are affected more than regular services
- FastMM:
- conditional defines that can help are
NeverSleepOnThreadContention
,UseSwitchToThread
, andUseReleaseStack
then measure. - has one huge advantage: It’s very, very good at keeping memory fragmentation at bay
- default settings are for applications that use lots of CPU, but have no really high memory allocation/deallocation rates
- has very good debugging facilities
- Under
FullDebugMode
address space is never released back to the operating system so once the address space has been exhausted there is very little room to manoeuvre.
- conditional defines that can help are
- TCMalloc:
- is very good at multi-threaded memory management with high allocation/deallocation rates
- needs to be persuaded to releases memory to the OS:
it only releases to the system under two occasions: Freeing another part of the memory, or asking it to release all parts marked as freed.- See methods
SetMemoryReleaseRate
andReleaseFreeMemory
in …/obones/tcmalloc-delphi/…/tcmalloc.pas
- See methods
- has no debugging facilities
The differences make it a challenge to integrate in your development and deployment process: because of the debugging facilities, you’d like FastMM in all your environments, but TCMalloc in multi-threaded environments with high allocation/deallocation rates.
One possibility is to have your CI environment deliver both in all stages, run all tests on both, then choose the final one depending on your run-time configuration.
That gives a burden on configuring your Continuous Integration, but the gain might outweigh this cost.
Relevant links from the Facebook thread:
- [WayBack] Sourceforge – TCMalloc : Thread-Caching Malloc
- [WayBack] The Delphi Geek: NeverSleepOnThreadContention–NOT!
- [WayBack] GitHub – grijjy/GrijjyFoundation: Foundation classes used by other Grijjy repositories
- [WayBack] GitHub – gperftools/gperftools: Main gperftools repository
- [WayBack] GitHub – obones/tcmalloc-delphi: A Delphi wrapper around the TCMalloc memory manager from gperftools
- [WayBack] TCMalloc : Thread-Caching Malloc
–jeroen