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 Object subclass: #GtVmMemoryConfigurationInstaller instanceVariableNames: 'activeConfiguration configurationsRegistry enabled dataThresholds' classVariableNames: '' package: 'GToolkit-Pharo-System' 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 Object subclass: #GtVmMemoryConfigurationInstaller instanceVariableNames: 'activeConfiguration configurationsRegistry enabled dataThresholds' classVariableNames: '' package: 'GToolkit-Pharo-System' are applied only if the installer is enabled.

GtVmMemoryConfigurationInstaller default  enable.
  

GtVmMemoryConfigurationInstaller Object subclass: #GtVmMemoryConfigurationInstaller instanceVariableNames: 'activeConfiguration configurationsRegistry enabled dataThresholds' classVariableNames: '' package: 'GToolkit-Pharo-System' defines a configuration for large object allocation in GtVmMemoryConfigurationInstaller>>#initializeForLargeObjectAllocationsConfiguration initializeForLargeObjectAllocationsConfiguration self configurationBuilderWithId: #forLargeObjectAllocation put: [GtVmMemoryManagement forLargeObjectAllocation]. .

GtVmMemoryConfigurationInstaller default 
	applyForLargeObjectAllocationsDuring:  [ "computation goes gere" ] 
  
GtVmMemoryConfigurationInstaller default 
	applyForLargeObjectAllocationsDuring:  [ "computation goes gere" ] 
	when: true "Boolean condition goes here as a parameter"
  

GtVmMemoryConfigurationInstaller Object subclass: #GtVmMemoryConfigurationInstaller instanceVariableNames: 'activeConfiguration configurationsRegistry enabled dataThresholds' classVariableNames: '' package: 'GToolkit-Pharo-System' defines a threshold for when a configuration should be activated based on the size of method source code in GtVmMemoryConfigurationInstaller>>#initializeMethodSourcesSizeThreshold initializeMethodSourcesSizeThreshold self dataThresholdAt: #methodSourcesSize put: (GtVmMemoryConfigurationBytesMemoryThreshold new thresholdValue: 5* 1024 * 1024) "5 MiB" .

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 ]