a) What exactly is the difference between rts_heap_size
and rts_memory_size
?
b) We are testing how big we can grow a Buffer
in a Motoko canister that is serialized into an Array in stable memory in the preupgrade
hook before we exceed the instruction limit. The Buffer is initalized from the Array in stable memory and in the postupgrade
hook we reset the stable variables to free memory.
memory size is the result of a call to Prim.rts_memory_size
and heap size the result of a call to Prim.rts_heap_size
. The order of call is
growBuffer
memory_size
- upgrade canister
-
heap_size
for each index in the table.
Growing transaction size to 4000000...
Upgrading...
βββββββββββ¬βββββββββββββββ¬βββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ¬βββββββββββββββββββββ
β (index) β canister β memory size before upgrade β heap size before upgrade β memory size after upgrade β heap size after upgrade β upgrade successful β
βββββββββββΌβββββββββββββββΌβββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββΌββββββββββββββββββββββββββββΌββββββββββββββββββββββββββΌβββββββββββββββββββββ€
β 0 β 'copying-gc' β '2.19 MB' β '0.7237930297851562 MB' β '17.69 MB' β '5.959255218505859 MB' β true β
β 1 β 'copying-gc' β '4.88 MB' β '2.0765953063964844 MB' β '52.56 MB' β '17.86111068725586 MB' β true β
β 2 β 'copying-gc' β '6.38 MB' β '4.254154205322266 MB' β '87.44 MB' β '29.76296615600586 MB' β true β
β 3 β 'copying-gc' β '12.75 MB' β '7.533042907714844 MB' β '174.56 MB' β '59.51760482788086 MB' β true β
β 4 β 'copying-gc' β '26.13 MB' β '15.255535125732422 MB' β '348.94 MB' β '119.02688217163086 MB' β true β
β 5 β 'copying-gc' β '57.13 MB' β '29.706295013427734 MB' β '697.56 MB' β '238.04543685913086 MB' β true β
β 6 β 'copying-gc' β '57.13 MB' β '38.922794342041016 MB' β '871.94 MB' β '297.55471420288086 MB' β true β
β 7 β 'copying-gc' β '98.56 MB' β '50.66817855834961 MB' β '1220.56 MB' β '416.5734405517578 MB' β true β
β 8 β 'copying-gc' β '125.50 MB' β '76.66597366333008 MB' β '1743.56 MB' β '595.1012725830078 MB' β true β
β 9 β 'copying-gc' β '214.94 MB' β '99.41592025756836 MB' β '2440.88 MB' β '833.1383819580078 MB' β true β
β 10 β 'copying-gc' β '284.06 MB' β '149.36919784545898 MB' β '3486.88 MB' β '1190.1940460205078 MB' β true β
βββββββββββ΄βββββββββββββββ΄βββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ΄βββββββββββββββββββββ
why is the heap size significantly bigger after the upgrade? for the memory size, i think it is because this number can only grow, but never shrink and throughout the upgrade process the canister somehow consumes this amount of memory. does it still hold true that we pay for Prim.rts_memory_size
, not for the actual memory being consumed by the canister?
c) what is the best way to determine the actual memory used by the heap? what is the best way to determine the actual memory used by the stable memory?