How to change the memory settings during a computation
Computations that need to create many large arrays, usually hundred of arrays larger then a few MBs, can run into a significant overhead because of garbabe collection.
A solution in these cases is to use GtVmMemoryConfigurationInstaller
to change the memory configuration and reduce the number of garbage collections during that computation.
These settings are usually not permanent, as they can signficantly increase the size of the image during normal usage.
All custom configurations done through the default instance of GtVmMemoryConfigurationInstaller
are applied only if the installer is enabled.
GtVmMemoryConfigurationInstaller default enable.
GtVmMemoryConfigurationInstaller
defines a configuration for large object allocation in GtVmMemoryConfigurationInstaller>>#initializeForLargeObjectAllocationsConfiguration
.
GtVmMemoryConfigurationInstaller default applyForLargeObjectAllocationsDuring: [ "computation goes gere" ]
GtVmMemoryConfigurationInstaller default applyForLargeObjectAllocationsDuring: [ "computation goes gere" ] when: true "Boolean condition goes here as a parameter"
GtVmMemoryConfigurationInstaller
defines a threshold for when a configuration should be activated based on the size of method source code in GtVmMemoryConfigurationInstaller>>#initializeMethodSourcesSizeThreshold
.
GtVmMemoryConfigurationInstaller default applyForLargeObjectAllocationsDuring: [ "computation goes gere" ] methodSourcesSize: 1233434 "Computed size"
GtVmMemoryConfigurationInstaller default dataThresholdAt: #methodSourcesSize put: (GtVmMemoryConfigurationBytesMemoryThreshold new thresholdValue: 50* 1024 * 1024) "50 MiB"
GtVmMemoryConfigurationInstaller default configurationBuilderWithId: #forLargeObjectAllocation put: [ GtVmMemoryManagement readFromVm growthHeadroom: 256 * (1024 ** 2); shrinkThreshhold: (1.5d0 * (1024 ** 3)) rounded; fullGcRatio: 2.0d0 ]