Skip to main content

Dark Matter

A dependency-graph-aware storage profiler for Homebrew.

CI Python Ruff Mypy prek License

Why

Homebrew flattens every dependency into a single Cellar directory. Tools like du or ncdu can tell you a formula takes up 500 MB, but they have no concept of why — whether that mass belongs to the formula itself or to a shared runtime pulled in by five other packages you installed for unrelated reasons.

Dark Matter reconstructs the dependency graph Homebrew already knows about and uses it to answer a more useful question: for each package you explicitly installed, how much disk space does it actually cost you, once shared dependencies are fairly split across everything that depends on them?

How it works

Dark Matter parses Homebrew's own JSON metadata (via brew info --json=v2 or its local API cache), rebuilds the dependency DAG, and walks it to compute two figures per package:

  • Core size — the package's own on-disk footprint (or, in theoretical mode, its compressed bottle archive).
  • Weighted recursive size — the core size plus a fair share of every transitive dependency, where each shared dependency's cost is divided evenly across all the packages that depend on it.

The ratio between the two — the Bloat Ratio — is the headline number. A low ratio means a package is mostly self-contained; a high ratio means most of its footprint belongs to shared infrastructure it happens to require.

Features

  • Comprehensive analysis suite
    • analyze — measures what's actually on disk, using brew info --json=v2 --installed and direct filesystem traversal (os.scandir) for exact byte counts.
    • leaderboard — a theoretical mode that ranks Homebrew's entire formula and cask catalog from the local API cache, without requiring anything to be installed.
    • inspect & compare — targeted O(1) theoretical resolution for individual or grouped packages without resolving the entire ecosystem payload.
    • explain — breaks down a target package's bloat by attributing fractional byte costs to each of its transitive dependencies.
    • export — streams the underlying DataFrames to CSV or JSON for integration into external data pipelines.
  • Fractional Attribution Model — shared dependencies (openssl, python, etc.) are divided proportionally across all parent packages instead of being double-counted, giving an honest per-package cost.
  • Daemon-free — no background indexing, no persistent database. Every run is a fresh, on-demand computation.
  • Typed and tested — fully type-annotated (strict mypy), linted with ruff, and covered by a pytest suite exercising the DAG traversal, fractional math, and network resolution logic. CI runs the full suite on macOS and Ubuntu across Python 3.12 and 3.14.

A note on theoretical measurements

leaderboard, inspect, compare, and explain rely on Content-Length headers from ghcr.io blob storage, which report compressed archive size, not the size a package occupies once unpacked to disk. The absolute numbers they report will therefore run lower than analyze's physical measurements.

The Bloat Ratio, however, stays meaningful. Since most bottles compress with similar algorithms (gzip or zstd), the compression factor $c$ appears in both the numerator and denominator and cancels out:

$$R \approx \frac{c \cdot m_{recursive}}{c \cdot m_{core}} \approx \frac{m_{recursive}}{m_{core}}$$

So while theoretical modes shouldn't be read as precise disk-space forecasts, they are a reliable way to evaluate relative bloat without installing anything.

Installation

git clone https://github.com/jacksonfergusondev/dark-matter.git
cd dark-matter
uv tool install --editable .

Usage

# Analyze what's actually installed
dark-matter analyze

# Rank the entire Homebrew catalog by theoretical bloat
dark-matter leaderboard

# Evaluate a specific formula instantly
dark-matter inspect uv

# Break down the dependency bloat of a specific package
dark-matter explain uv

# Compare multiple packages side-by-side
dark-matter compare uv poetry pdm

# Export the entire graph to JSON for external analysis
dark-matter export --format json > homebrew_bloat.json

All commands accept the global --verbose / -v flag for debug logging, and --version to print the installed version.

analyze

Flag Default Description
--sort / -s ratio Sort by ratio, core, or recursive
--top / -n 20 Number of packages to display
--fractional / --standard --fractional Toggle the Fractional Attribution Model

leaderboard

Flag Default Description
--sort / -s ratio Sort by ratio, core, or recursive
--top / -n 20 Number of packages to display
--arch / -a arm64_tahoe Target bottle architecture

inspect

Argument/Flag Default Description
[PACKAGE] Required The target package to analyze
--source / -s installed Data source to compute: installed or catalog
--arch / -a arm64_tahoe Target bottle architecture

compare

Argument/Flag Default Description
[PACKAGES]... Required A space-separated list of packages to compare
--sort / -s ratio Sort by ratio, core, or recursive
--source / -s installed Data source to compute: installed or catalog
--arch / -a arm64_tahoe Target bottle architecture

explain

Argument/Flag Default Description
[PACKAGE] Required The specific package to analyze
--source / -s installed Data source to compute: installed or catalog
--arch / -a arm64_tahoe Target bottle architecture

export

Flag Default Description
--source / -s installed Data source to compute: installed or catalog
--format / -f csv Output format: csv or json
--arch / -a arm64_tahoe Target bottle architecture (for catalog source)

Development

The project uses just to wrap common tasks:

just format       # ruff format + fix
just lint         # ruff + rumdl
just typecheck    # mypy
just test         # pytest
just test-cov     # pytest with coverage report
just ci           # the full pipeline CI runs, locally

📧 Contact

GitHub LinkedIn Email

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dark_matter_cli-0.1.0.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dark_matter_cli-0.1.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file dark_matter_cli-0.1.0.tar.gz.

File metadata

  • Download URL: dark_matter_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dark_matter_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cfe5a7b08b7682f35f363e1652b5211290044cc02ecd224b4e093a4b8d122d25
MD5 2876ee614a4fee8449467525901b68be
BLAKE2b-256 bb130820810e3e9d445c332f0d36138b9ddca5b3bc49765d55d0352b7ec0d175

See more details on using hashes here.

Provenance

The following attestation bundles were made for dark_matter_cli-0.1.0.tar.gz:

Publisher: release.yml on JacksonFergusonDev/dark-matter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dark_matter_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dark_matter_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for dark_matter_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bed8a2c4a3cb23d1bfac305714e2eb620aaf95ed8aa4862e413aa2b8e2eeb8c
MD5 762d5df0f8cafdd25861e3d872d38f05
BLAKE2b-256 4d00747be95c2fd7d23e55c9011ebe5bc7229aad07d79e95dd9452da2afafe33

See more details on using hashes here.

Provenance

The following attestation bundles were made for dark_matter_cli-0.1.0-py3-none-any.whl:

Publisher: release.yml on JacksonFergusonDev/dark-matter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page