<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucid 001</title>
    <description>The latest articles on DEV Community by Lucid 001 (@lucid_001_a6d7dcda4edfa67).</description>
    <link>https://dev.to/lucid_001_a6d7dcda4edfa67</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4275151%2F83e66887-5a03-4b42-ba31-b3e6735b5d57.png</url>
      <title>DEV Community: Lucid 001</title>
      <link>https://dev.to/lucid_001_a6d7dcda4edfa67</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucid_001_a6d7dcda4edfa67"/>
    <language>en</language>
    <item>
      <title>How I Built a Lossless macOS APFS Storage Optimizer in Rust (Without Deleting Files)</title>
      <dc:creator>Lucid 001</dc:creator>
      <pubDate>Mon, 30 Nov 2026 22:27:13 +0000</pubDate>
      <link>https://dev.to/lucid_001_a6d7dcda4edfa67/how-i-built-a-lossless-macos-apfs-storage-optimizer-in-rust-without-deleting-files-4p5h</link>
      <guid>https://dev.to/lucid_001_a6d7dcda4edfa67/how-i-built-a-lossless-macos-apfs-storage-optimizer-in-rust-without-deleting-files-4p5h</guid>
      <description>&lt;p&gt;If you use a 256 GB or 512 GB MacBook, you eventually run into the "Your disk is almost full" wall. Most Mac cleaners solve this by deleting caches and logs, or charging a subscription to show you big folders.&lt;/p&gt;

&lt;p&gt;I wanted something different: a free, open-source tool that reclaims real space from the files I actually want to keep, without deleting a single file or re-encoding photos and videos.&lt;/p&gt;

&lt;p&gt;So I built &lt;strong&gt;&lt;a href="https://github.com/subwaycookiecrunch/ketodisk" rel="noopener noreferrer"&gt;ketodisk&lt;/a&gt;&lt;/strong&gt; in Rust.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it shrinks files without changing a single byte
&lt;/h2&gt;

&lt;p&gt;macOS APFS already has strong space-saving primitives built into the filesystem, it just rarely applies them to existing user files on its own. Existing open-source tools like &lt;code&gt;afsctool&lt;/code&gt; or &lt;code&gt;ditto --hfsCompression&lt;/code&gt; only handle one piece of the puzzle.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ketodisk&lt;/code&gt; puts three native APFS mechanisms behind one cost planner:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Exact duplicate CoW cloning (&lt;code&gt;clonefile&lt;/code&gt;)&lt;/strong&gt;: If you have identical copies of a file across folders, APFS can point both entries at the same physical blocks on disk. If the file is also compressible, &lt;code&gt;ketodisk&lt;/code&gt; compresses once so the clones share the compressed extents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native transparent LZFSE compression (&lt;code&gt;com.apple.decmpfs&lt;/code&gt;)&lt;/strong&gt;: macOS supports transparent filesystem compression using Type 11 inline extended attributes (for small files) and Type 12 resource forks with &lt;code&gt;UF_COMPRESSED&lt;/code&gt; (for larger files). Finder, Spotlight, and your apps keep reading everything normally. There are no &lt;code&gt;.zip&lt;/code&gt; archives to unpack.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed-offset 4 KiB near-duplicate block sharing&lt;/strong&gt;: Unlike Btrfs or XFS on Linux, APFS does not expose &lt;code&gt;FICLONERANGE&lt;/code&gt; for arbitrary block-range deduplication. For large similar files (append-only logs, datasets, page-modified images), &lt;code&gt;ketodisk&lt;/code&gt; clones a base file and selectively overwrites only the differing 4 KiB blocks when that saves more space than compressing each file independently.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Architecture and chasing a 30x speedup
&lt;/h2&gt;

&lt;p&gt;The core planner, scanner, and CLI are written in Rust, paired with a small C shim compiled directly against the macOS SDK headers. Using a thin C layer meant I did not have to hand-maintain fragile struct layouts for &lt;code&gt;getattrlist&lt;/code&gt;, &lt;code&gt;decmpfs&lt;/code&gt;, and &lt;code&gt;proc_listpidspath&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Early prototypes crawled at around &lt;strong&gt;2.3 MiB/s&lt;/strong&gt; on cold trees with lots of small files because of per-file syscall and staging overhead. After reworking the staging pipeline and parallelism, throughput jumped to &lt;strong&gt;~70 MiB/s&lt;/strong&gt; on Apple Silicon (a 1,000-file synthetic tree finishes end-to-end with full hash verification in roughly 3.3 seconds).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it won't corrupt your files
&lt;/h2&gt;

&lt;p&gt;Modifying user files in place is high stakes, so the entire pipeline is preview-only by default and fail-closed on every write:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strict skipping&lt;/strong&gt;: Automatically skips &lt;code&gt;SF_DATALESS&lt;/code&gt; iCloud placeholders (so scanning will never accidentally trigger massive iCloud downloads), &lt;code&gt;.app&lt;/code&gt; bundles, hardlinks, immutable files, and active SQLite WAL/SHM file sets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verified atomic swaps&lt;/strong&gt;: Before replacing any file, &lt;code&gt;ketodisk&lt;/code&gt; stages a temp copy, reads it back to verify the full SHA-256 hash matches byte-for-byte, checks &lt;code&gt;proc_listpidspath&lt;/code&gt; for other processes holding the file open, swaps via &lt;code&gt;renamex_np(..., RENAME_SWAP)&lt;/code&gt;, and runs a post-swap verification before unlinking the displaced copy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fault-injection testing&lt;/strong&gt;: The test suite has 55 tests, including 24 live APFS fault-injection tests covering mid-stage aborts, open-FD races, modification drift rollbacks, and journaled crash recovery (&lt;code&gt;ketodisk doctor --clean-temp&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;p&gt;No disk tool is magic, and it helps to be upfront about the limits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Live databases and active VMs&lt;/strong&gt;: APFS returns &lt;code&gt;ENOTSUP&lt;/code&gt; for &lt;code&gt;exchangedata(2)&lt;/code&gt;. From unprivileged user-space, there is still an irreducible race if another process already holds a writable file descriptor or &lt;code&gt;mmap&lt;/code&gt; and &lt;code&gt;proc_listpidspath&lt;/code&gt; is restricted. Everything is documented in &lt;code&gt;SECURITY.md&lt;/code&gt;, and you should not run &lt;code&gt;ketodisk&lt;/code&gt; on active databases or running VM images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Already-compressed media&lt;/strong&gt;: MP4s, JPEGs, and ZIP archives will not shrink much further (unless you have exact duplicates).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1-byte shifts&lt;/strong&gt;: Fixed-offset 4 KiB matching breaks if data shifts by a byte; the planner detects this and falls back safely.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Finder free-space lag&lt;/strong&gt;: If you use Time Machine, local APFS snapshots hold onto old blocks until macOS prunes them (usually within 24 hours), so Finder may not reflect the reclaimed gigabytes immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it safely on dummy files
&lt;/h2&gt;

&lt;p&gt;You can install it via Homebrew (built from public source, MIT licensed, zero telemetry):&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
bash
brew install subwaycookiecrunch/tap/ketodisk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>rust</category>
      <category>showdev</category>
      <category>macbook</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
