Hive is an append-only data store. When you change or delete a value, the change is written to the end of the box file. Sooner or later, the box file uses more disk space than it should. Hive may automatically "compact" your box at any time to close the "holes" in the file.
It may benefit the start time of your app if you induce compaction manually before you close a box.
var box = Hive.box('myBox');
await box.compact();
await box.close();You can specify your own rules for automatic compaction. Just pass the compactionStrategy parameter when you open a box:
var box = await Hive.openBox('myBox', compactionStrategy: (entries, deletedEntries) {
return deletedEntries > 50;
});The compactionStrategy above will compact your box when 50 keys have been overridden or deleted.
!> NEVER access a box from the compaction strategy.