Stable memory data pages alignment

Hey there.
Straight to the point. IC’s stable memory exists in form of pages of 64k size. Is it cheaper to work with aligned by page size data and does it even make sense to align data in our super-virtual environment?

What I mean by alignment is - imagine I have allocated (stable_grow()) two pages of stable memory and I have some data to store.
Now I have a choice:

  1. I can ignore pages completely (and the API actually wants me to do this) and just store my data like this:
     page 1          page 2
[somedata-another][data----------]
  1. Or I can teach my program to understand pages and to align data according to their size like this:
     page 1          page 2
[somedata------][anotherdata-----]
2 Likes

Alignment should be irrelevant. However, what you may want to optimise for is locality, i.e., organising your data such that typical data mutations touch only nearby data, ideally in one page or a minimum number of pages. Because the number of modified pages may affect cycle cost.

2 Likes