rust-lang / rust-lang/cargo

macOS slowdown due to temporary files outside of Library/Caches

Open
#8,684 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug O-macos Performance S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

I've noticed that when I'm working on Rust projects, macOS processes mds and mds_worker are consuming high amount of CPU and disk I/O. These processes are indexing the disk for macOS Spotlight search functionality. I suspect churn of large numbers of files in target/ subdirectories like .fingerprint and incremental causes Spotlight to continually rescan and reindex these directories.

macOS expects well-behaved applications to use ~/Library/Caches or /tmp for all temporary files, so it doesn't have any official APIs for reducing negative impact of file churn elsewhere. Officially the only way to exclude folders from Spotlight is to add them as "private" in GUI settings, which is cumbersome.

I see two ways of fixing this problem:

  1. Move build, incremental to a subdirectory in ~/Library/Caches/Cargo.
  • The subdirectory could be derived from a hash of dest dir, so that these directories remain separate.
  • Optionally the could be moved to the correct temp dir only if CARGO_TARGET_DIR is not set, so that users who have customized CARGO_TARGET_DIR are not surprised by files being put elsewhere.
  • Optionally there could be symlinks in target/ to the new temp location, so that 3rd party utilities that peek into Cargo's internals continue to work.
  1. or rename them to build.noindex, incremental.noindex. This naming convention is a poorly documented way of excluding folders from Spotlight indexing. It isn't as good as using ~/Library/Caches, but would solve the Spotlight issue with a smaller change to Cargo's behavior.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating Cargo's handling of target/ directories, especially build and incremental, along with the CARGO_TARGET_DIR behavior described in the issue. Compare the proposed Library/Caches relocation and .noindex naming approaches, including compatibility implications for users and third-party tools. Done means selecting and implementing a clearly scoped approach that reduces Spotlight churn without breaking expected target-directory behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.