In .NET 9, Microsoft has introduced Dynamic Adaptation to Application Sizes (DATAS) as the default garbage collection (GC) mode, aiming to make applications more responsive to their actual memory needs. This approach ensures that an application’s heap size aligns with the volume of its long-lived data, allowing for dynamic adjustments based on workload fluctuations.
How DATAS Operates
- Allocation Limits: It determines the maximum allocations permitted before initiating the next GC cycle, based on the size of long-lived data. This helps in keeping the heap size in check.
- Throughput Consideration: While focusing on memory constraints, DATAS also takes application throughput into account to maintain performance.
- Heap Management: Starting with a single heap, DATAS can adjust the number of heaps as needed. If multiple threads are allocating memory, it can increase the number of heaps to enhance throughput and reduce waiting times. Conversely, it can decrease the number of heaps when the demand is lower.
- Compacting Collections: When necessary, DATAS performs full-compacting GCs to prevent excessive fragmentation.
Benefits of DATAS
The primary advantage of DATAS is its adaptability. For applications with variable workloads, DATAS ensures that memory consumption scales appropriately, reducing during periods of low demand and expanding when needed. This dynamic adjustment is particularly beneficial in environments with limited memory resources, as it allows for better capacity planning and resource utilization.
Disabling DATAS
While DATAS offers significant benefits, there might be scenarios where a fixed GC mode is more suitable. If you observe a decrease in throughput or have specific application requirements, you can disable DATAS by setting the DOTNET_GCDynamicAdaptationMode environment variable to 0, adjusting the System.GC.DynamicAdaptationMode setting in the runtimeconfig.json file, or configuring the GarbageCollectionAdaptationMode MSBuild property to 0.
Conclusion
During the .NET 9 release we saw a lot of hype from a lot of people claiming their applications had a reduced memory footprint. Well this is why. Hope this helped, see you in the next one.
Affiliate promo
If you love learning new stuff and want to support me, consider buying a course from Dometrain using this link: Browse courses – Dometrain. Thank you!
Leave a comment