← all writing

making mamaskin’s offline database 47% smaller

i just wanted mamaskin to take up less space on people's phones. that was pretty much the starting point.

47.14% smaller. every previous product kept, plus 481 new ones. sizes shown here are rounded, and refer to the database file.

i'd already done some work to reduce the code size on android, including r8 minification, and i was looking at what else i could make smaller. mamaskin is my skincare ingredient checker for pregnancy and breastfeeding. it comes with a sqlite database of products so people can use parts of the app offline. that seemed like a good place to look next.

at first, i was open to including fewer products offline if it meant a smaller app, especially on android. but i wanted to understand what that would mean for someone using it before deciding.

in the end, the database went from 66,506,752 bytes to 35,155,968 bytes, a 47.14% reduction. it still had all the previous products, plus 481 new ones.

the saving came from changing how the data was stored. i also needed to check that the app could read it properly and that the main features still worked.

ok so what should i do now?

a lot of the app uses that database. search is an obvious one, but the for you page also uses local data to choose which products to show and in what order. removing something could change the recommendations or make a page slower to load.

i used codex with gpt-6.1 set to high for this. first i asked it to look at the options. could we remove some data? could some of it stay online? were we wasting space on things like image urls? i wanted to know what each option would save and what problems it might cause.

i knew the app, so i could point codex towards the features i thought would be affected and ask it to check my assumptions against the code. asking it to work through the whole app from scratch takes time and a lot of tokens. i started with what i already knew and asked it to check that against the code.

for example, i wanted to check which data the for you page already had on the phone and which it fetched online. tags for when to use a product and whether it was suitable were stored locally and used to pick products. those stayed in the database.

before moving anything online, i wanted to know where the app used it, what we'd have to change, and what would happen without a connection.

after looking at the options, i went with making the image urls and repeated data take up less space, while keeping what the main features needed. codex made the changes to the database and the code that reads it.

that meant changing a few things.

search was keeping an extra copy of the product text. it could use the product names and brands already in the database instead. it still needed to find the same products in the same order.

lots of image addresses also started with the same long bit of text. the database could store that once, then the app could put the full address back together when it needed it. the images were already online, and putting the address back together happened on the phone without another network request.

a simplified example of sharing the start of an image url. the app puts the full address back together on the phone.

then there were product details that kept repeating. things like categories, suitability tags, usage tags and review notes. common values could be stored in a shorter form and turned back into text when read. less common values stayed as they were.

the app needed a few changes to read this version of the data. for you also got simple flags showing whether a product had suitability or usage tags. that let it sort products without unpacking long bits of text just to see if there was anything there.

ok, but does it still work?

i wanted a smaller app, but the main features still had to work. losing something useful just to save a bit of space wouldn't have been worth it.

i went through search and the other features, checked that things loaded, and tried the app online and offline.

some features needed a connection. product pages could still show the saved assessment score offline, which was something i wanted to keep.

the bit i wanted to keep: opening a product and seeing its saved score, even without a connection.

i wanted to keep that working because of the feedback, research and analytics i'd looked at. i remember a support request from someone who mainly looked at the score, then later noticed that the ingredient list was different from the one on their bottle. that was one of the examples i had in mind.

the database checks compared 122 searches and 122 scan lookups against a regular database built from the same catalogue. all of those cases returned the same products in the same order. the scan checks covered finding products in the database, separate from using the camera. there were also checks for manually added notes and missing scores.

a couple of fixes came up while preparing it. one was making sure the code could see the new fields so manual notes still showed up. another was handling an empty lookup dictionary in the database builder. i don't remember needing another round of changes after trying it myself.

the new database had 107,917 products. all 107,436 previous product ids were still there.

the 47.14% is the difference between the old database file and the new one. the catalogue had also been updated, so there were separate checks using the same data in both formats.

the smaller database went into the ios and android 1.3.8 builds. the build checks also confirmed the old file was left out.

← back to writing