bbolt on iOS

bbolt is an embedded pure Go key/value store that I have been successfuly using for my projects for a couple of years. When working on scuttlego it became my first choice for the database layer thanks to the ease of use and aforementioned characteristics.

One of the bbolt's main design choices is mmaping the entire database file. This has a number of benefits but uses up virtual memory allocated to the program. This is normally not a problem on most operating systems.

Scuttlego's first main purpose will be running on iOS as Planetary is mainly used on iPhones. When testing bbolt with scuttlego I eventually encountered strange panics which I tracked down to a failing mmap call returning the following error: "mmap allocate error: cannot allocate memory". This seemed quite strange to me and I've never had any similar problems with bbolt on other platforms. The issue seemed to always happen around the time the database file grew to around 500 megabytes. After a bit of digging around I discovered an unexpected characteristic of the platform we were running on: the virtual memory on iOS seems to be practically limited to around 500-700 megabytes. This is a result of the underlaying technical implementation.

I am not entirely sure if this implies that unfortunately bbolt can't run on iOS or if there is a workaround that could be applied. I considered modifying bbolt to map the database file in parts but this didn't seem practical. Due to those problems and a lack of better ideas I decided to move scuttlego to a different database system for now. Right now the most promising candidate seems to be Badger.

Related reading:

2022-12-26