GitHub 0
Skip to content

How it stays fast

whatfrees asks the owner of each thing first, walks only what no one sized, stops at a deadline, and counts a hard-linked file once.

A scan has a budget of 5 seconds. Three habits keep it inside that.

The owner of a thing already knows its size and its state. whatfrees asks the owner before it reads a single file.

  • Git. A checkout's .git file, HEAD, commondir, packed-refs and stash log are read from disk. No subprocess runs for them. One git rev-list per repository tells which HEADs no remote has. git status runs only for a checkout nothing cheaper has decided.
  • The process table. One read of every working directory (/proc on Linux, lsof on macOS) tells which checkouts are in use.
  • Settings files. The pnpm store path comes from the environment, pnpm/rc and ~/.npmrc. pnpm doesn't start.

A source that can't answer in time is skipped and named in skipped. The rest of the report still prints.

What no owner sized, a pool of four worker threads walks. It never follows a symlink and never crosses into another file system.

The likeliest deletions go first: orphan, then safe, ask, unchecked, unsaved, and live last. git status gets half of what is left of the budget, and sizing gets the rest.

When the deadline comes, a tree still being read returns what was counted so far. Its precision is lower-bound, and the text report prints it as ≥4.2 GB. A tree the walker never reached is unmeasured. The report sets partial to true, and its next list suggests a longer budget.

FlagEffect
--budget 10Ten seconds for the whole scan
--budget 0Owners answer, nothing is walked. Owners get a short floor even then
--exactNo deadline and no size cache. Every tree is read to the end

du counts a file once however many links it has. That isn't what deleting frees. A file with a second link outside the folder stays on disk.

whatfrees counts disk blocks per inode and splits them in two:

FieldMeaning
freesBlocks of files whose links are all inside the folder
sharedBlocks of hard-linked files that a link outside the folder keeps
apparentfrees + shared, what du prints

A pnpm or bun project links its node_modules files to the store. Deleting the project frees little of them, and deleting the store frees little while projects still link to it. shared shows that.

Sizes come from st_blocks, so a sparse file counts the blocks it uses, not the length it claims.

A report is always whole entries. A budget cut never leaves half an entry. Three fields say what is missing:

  • partial is true when a source or a walk didn't finish.
  • skipped names each source that had no answer, with budget, error or remote as the reason.
  • Each entry's bytes.precision says how far to trust its size. See the JSON report.

A single file's size is stored in measure.json, keyed by path and modification time, and checked against the file's current blocks and link count before it is used. A hit sets cached: true on the entry. Directories are never cached, because a directory's stat says nothing about what is under it. See Installation for the folder. --no-cache skips it.