How it works
Coldpack is patient. It waits until a file is cold, checks that compression pays, and only then touches it.
Finding files
The watcher
Coldpack listens to file events for the folders you chose. It keeps only events for files that were created, modified, renamed or removed. A modified file becomes hot: it enters the hot set with the time of the change. Only a file that could be a candidate gets a row: a regular file of at least 16 KiB, with one link, not yet compressed, and with its data on this Mac. Tiny files and hard-linked files never enter the set.
Coldpack saves the id of the last event batch it stored. After a restart it asks the system to replay events from that id, so changes made while it was off are not missed.
The cooldown
A hot file waits for the cooldown (default 6 hours) after its last change. Then it is due. Files that are open in any process are pushed back: Coldpack reads the list of open files once, caches it for 30 seconds, and puts an open file back in the hot set.
The scan pass
Events only tell Coldpack about new changes. To find files that were already cold, it walks your folders once. The walk is resumable: Coldpack saves the last file it handled, and after a restart it continues after that file. Siblings are visited in a fixed order so a resume never skips or repeats a file. The walk runs at low disk priority. Files older than the cooldown go straight to the work queue. Files changed more recently go to the hot set. A folder that a "never compress" rule names is not entered at all.
If the system drops events (for example under heavy load), Coldpack walks the affected folders again. A switch of dry run, or a change of scope or rules, starts the right walk too: new folders are scanned alone, and a rule change walks everything again.
Deciding what pays
For each due file Coldpack runs these checks in order:
- Eligibility. The file must be a regular, non-empty file, owned by you and writable, not already compressed, with one link, not sharing blocks with a clone, without a resource fork, and with no flags other than the hidden and no-dump flags. It must be at least the minimum size, and the volume must have the file size plus 256 MiB free.
- Open check. A file that is open anywhere is postponed.
- Known formats. Archives, images, audio, video, fonts, PDFs and similar formats are already compressed. Coldpack knows 49 extensions and the starting bytes of many formats, and it skips them without a sample.
- Sample. Coldpack compresses the first 64 KiB with LZFSE. If the result is larger than 85 % of the original (the ratio threshold), it skips the file.
- Real saving. Coldpack counts what the file would really free, rounded to disk blocks. If that is less than 4,096 bytes, it skips the file.
It learns
Coldpack groups files into classes by extension and folder (digits in the folder name are collapsed, and a rotation suffix is understood, so app.log.7 is in the class log.#). After two samples of a class:
- all good: the class is compressible and Coldpack stops sampling it;
- all bad: the class is incompressible and Coldpack skips it, but samples every 25th skipped file to stay honest;
- mixed: Coldpack samples each file.
Backing off from busy files
A compressed file that comes back uncompressed was rewritten by an app, as logs and databases are. Coldpack remembers this and waits longer each time: 1, 2, 4, 8, 16 and at most 32 days (the default schedule; the engine does not read the Advanced settings for it yet). It does the same for a folder: when three files of one folder pattern come back, the whole pattern backs off. Coldpack does not fight your apps.
| Strike | File waits |
|---|---|
| 1 | 1 day |
| 2 | 2 days |
| 3 | 4 days |
| 4 | 8 days |
| 5 | 16 days |
| 6 or more | 32 days (the limit) |
What counts as a saving
Coldpack reports only the space that is really freed. For a file that shares part of its blocks with a clone, it counts only the bytes that belong to that file alone. The dry-run estimate, the saved total and the minimum-saving check all use the same number.
Housekeeping
About once a day, when the Mac is idle, Coldpack tidies its own state: it forgets files that are gone, lets old backoffs decay, drops unused learned classes, removes leftover journal files, rotates the log above 5 MB (keeping one old file) and compacts its database. coldpack maintain does the same by hand. The state database stays small: it keeps a row only for files that wait for their cooldown and for files that were compressed or are backing off.