IC Stable Structures - default page allocation

Hi,

I’m creating a scalable archive solution. As part of the solution, I regularly check the stable memory size of an archive canister. It works fine. However, in testing with PocketIC ( rust ), I notice that my archive canister spins up with around 129 pages of stable memory. This means I have to insert a lot of data to my archive and set a threshold of 8MB for when a new archive canister should be created. Based on previous discussions i’ve had around ic-stable-structures I know that 8MB is allocated by default right?

Is there a way I can limit or set the amount of memory allocated for the StableBTreeMap when it is initialized?

Thanks,

Freddie

Ignore,

I forced the bound in my storable type to be artificially high for testing.


impl Storable for MyType {
    fn to_bytes(&self) -> Cow<[u8]> {
        Cow::Owned(Encode!(self).unwrap())
    }
    fn from_bytes(bytes: Cow<[u8]>) -> Self {
        Decode!(&bytes, Self).unwrap()
    }
    const BOUND: Bound = Bound::Bounded {
        max_size: 100_000,
        is_fixed_size: false,
    };
}

the higher i make max_size, the faster the page fills up. this means i have to insert a lot less data to fill up the pre-allocated memory that ic-stable-structures initializes

2 Likes