Fast way to zeroize stable memory?

I was wondering if it is possible to add system API to zeroize 64-bit stable memory?
Something like stable64_zeroize(pages_offset, pages_count).

I’m working on stable collections in ic-stable-memory and for now some of these collections are limited in size because of that. For example a SHashMap requires you to zeroize the whole block of memory, before using it and right now I’m doing it by creating a cleaning vector vec![0u8; SIZE] and writing it into the desired position in stable memory which is both: expensive and limited (since I can’t create a Vec bigger than 4GBs). So the maximum size of a SHashMap is also limited to 4GBs.

There is a workaround - you can write this cleaning vector multiple times to different locations, but I’m afraid this would simply make a canister hit message limit. I believe there should be a lower level (and much cheaper) API to physically discharge bits to zeros that can be exposed through IC’s API, but maybe I’m wrong.

2 Likes

Look into Wasm bulk memory operations. The replica should accept them, but your SDK may have trouble generating those bytecodes. Which language are you interested in?

Are these bulk operations exposed?

I’m from team rust.

I am particularly interested in the type of collections you are building?

Stable memory can only be interacted via functions; it’s not exposed as a wasm memory and so wasm bulk memory operations can’t touch it to my knowledge.

Ooops, you are right. I missed the “stable memory” part. But not all is lost! @senior.joinu feel free to lobby for (stable memory) system call API equivalents of Wasm bulk memory instructions.

EDIT: I searched and finally found it…
This is the thread where you can voice your wish: Improving the utility of stable memory - #3 by johan