A Rust reimplementation of the Tangled knotserver.

target/ dir bloat: integration tests + sqlx macros + no GC = 80+ GB #2

Open isaaccorbrey.com
Open opened by isaaccorbrey.com

cargo clean reclaimed 81.9 GiB from target/ on 2026-05-24. Root causes, in order of impact:

  1. Integration tests as separate binaries (~biggest lever)

Every file in mnemosyne_tests/tests/*.rs compiles as its own statically-linked binary. 27 files × ~60–75 MB per binary × multiple stale hashed copies = many GB of redundancy.

Each test binary statically links the full crate graph (sqlx, tokio, bollard, gix, reqwest, mnemosyne_protocol, mnemosyne_ssh, mnemosyne_xrpc, ...).

Fix: Consolidate into a single tests/all.rs with mod protocol_clone; mod ssh_push; .... Standard pattern, ~27× reduction in integration test artifact size. See https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html

  1. sqlx compile-time query verification

libsqlx_postgres had 1.4 GB across 141 stale versions in target/debug/deps/. The query!() macro re-runs against the DB on every change, triggering full recompilation and leaving the old .rlib behind.

Fix: Use sqlx offline mode — SQLX_OFFLINE=true + commit .sqlx/ query metadata. Eliminates the recompile cascade.

  1. No automatic GC of stale artifacts

Cargo never deletes old hashed artifacts. 154,978 files in deps/ before cleanup; many were stale copies from old commits.

Fix: Add cargo-sweep to dev tooling. Run cargo sweep --time 14 periodically (or as a pre-commit / scheduled job) to drop artifacts untouched for 14 days.

  1. Incremental compilation cache uncapped

target/debug/incremental/ was 15 GB. Rustc's incremental cache grows unbounded.

Fix: Consider disabling incremental for this project (CARGO_INCREMENTAL=0) if CI does fresh builds anyway, or accept it but include incremental/ in cargo sweep scope.

Stretch

  • Set CARGO_TARGET_DIR to a shared location across all Rust projects so they share dependency builds (not specific to mnemosyne, but related).
Sign up or Sign in to add to the discussion.