Direct Integration with Bitcoin

Hey folks, I am the author of StableBTreeMap. I was out the past two weeks so my apologies for being a bit late to the party.

Yes, it is absolutely possible to use StableBTreeMap within a canister as has already been demonstrated by @ovictor, and it was initially designed with that intent in mind.

Currently, we are prioritizing getting the bitcoin integration working over making the StableBTreeMap usable for canisters, but given the interest, I can create a small demo repo of how to use the StableBTreeMap within a canister for those who are interested.

There are some caveats here that are worth noting with using StableBTreeMap within a canister:

  1. We didn’t do any in-canister profiling to measure how many instructions are required to access an element in StableBTreeMap vs a standard BTreeMap. StableBTreeMap is expected to consume more instructions, but we haven’t yet looked into how much more compared a standard BTreeMap. Depending on your use-case, this may be a factor to consider.

  2. With one single stable memory, the only way to have multiple instance of StableBTreeMap is to allocate, say, X memory pages to the first StableBTreeMap, Y memory pages to the second StableBTreeMap, etc. This leads to developers having to allocate potentially memory than they really need, and it does put some constraints in terms of how big your StableBTreeMap can grow. This caveat will be addressed once the IC supports multiple memories.

There are also some changes to the API that I plan to do (e.g. support for generics), that will make the data structure easier to work with and closer to a standard BTreeMap in terms of its API semantics.

I’ll aim to have a demo repo to share with you folks by end of next week.

Update: I created some examples that you can find in this thread.

23 Likes