I’m surprised that you didn’t hit issues with the compacting GC before 1.5GB
Is your heap size actually 4GB when you call Prim.rts_heap_size()
? Or are you referring to your canister’s memory size Prim.rts_memory_size()
?
If you’ve gotten to the point where the GC is blocked (too much garbage to collect over a few rounds of DTS consensus), then you’re in danger of your canister becoming unresponsive to additional insertions. This is where the incremental GC should shine (allowing you to use the full 4GB heap).
You should be able to activate the incremental GC before the 0.15.3 dfx release by following these instructions - Incremental Garbage Collector Beta Release: Motoko Update Part 12
One additional area of improvement suggestion I might recommend. The TrieMap in motoko base isn’t nearly as memory efficient as some of the other libraries out there. Collection libraries | canister-profiling has statistics on a few of the currently available map libraries out there. Maybe look into a data migration that can save you space while you’re at it!