About most suitable stable mapping collection data structure to use for official examples repo

I’ve just completed work on updating the invoice canister for the BNT-2 bounty.

The most significant upgrade is support for the ICRC1 token standard, which I did by extending the work and motivation of Kyle’s original implementation and hope it will be just as helpful. To that end, while not specifically a part of the bounty’s tasks, I thought it might be worthwhile to update the use of the conventional hash-map as since the original release date of the invoice canister, there’s more options for a stable memory mapping collection if anyone has any input on what might suitable for a project in the official Dfinity examples repo. Or I can just leave it as is so that a developer can easily swap it out to their preference. Thanks for your time.

4 Likes

Totally agree.

Depending on what data structures the app uses, there is (at least) a stable buffer and a couple of “stable BTrees” (which could each replace uses of a hash map, with some adjustments) as well as a stable hash map:

My sense is that these are but only three options of many, and other people may have more.

Relatedly, there’s also this table of performance results that compares different map options, though most of them are not “stable”.

2 Likes

Thank you, this is particularly important as I just learned trapping in the preupgrade hook can put a Motoko canister into an irrecoverable state.

1 Like