Skip to content

App: Add safe Xcode UserData cache cleanup#61

Open
alexandre-g wants to merge 1 commit intovashpan:masterfrom
alexandre-g:feature/safe-xcode-userdata-cleanup
Open

App: Add safe Xcode UserData cache cleanup#61
alexandre-g wants to merge 1 commit intovashpan:masterfrom
alexandre-g:feature/safe-xcode-userdata-cleanup

Conversation

@alexandre-g
Copy link
Copy Markdown

Summary

  • add a new UserData Cache cleanup category for safe, regenerable Xcode data under ~/Library/Developer/Xcode/UserData
  • include only explicit cache-like folders:
    • Previews
    • IB Support/Simulator Devices
    • Capabilities
  • exclude editor preferences and other persistent user settings from this new cleanup scope
  • add CLI support for the new category via user-data-cache
  • update the README and in-app manual to document the new cleanup area
  • improve scan performance by avoiding duplicate size walks during the same scan while preserving the original recalculateSize() semantics

Why

Xcode stores a meaningful amount of disposable data outside the app’s existing cleanup categories, especially in preview-related UserData folders. Those directories can grow very large over time, but they are safe to regenerate and are good candidates for cleanup.

While adding support for those folders, scan performance became noticeably slower because some large directory trees were being traversed twice in a single scan:

  • once to precompute child sizes for size-based sorting
  • again when aggregating the parent entry size

This PR keeps the existing behavior and ordering, but removes that duplicate work in the scan path without weakening the semantic contract of the general-purpose size recalculation APIs.

The feature was requested in this Issue: #60
And also expected to be working on reddit

I actually already have DevCleaner installed and I have used it. But when using DevCleaner this time it is not actually showing these large 59 GB files and I don't know why. But thanks for your comment anyway!

What changed

  • added XcodeFiles.Location.userDataCache
  • added a UserData Cache root entry in the scan model
  • implemented scanUserDataCacheLocations() to discover only explicit, regenerable cache folders under Xcode/UserData
  • kept size-based ordering for those entries
  • added CLI parsing and help text for user-data-cache
  • updated README.md and DevCleaner/Resources/Manual/manual.html to describe the new cleanup category
  • restored XcodeFileEntry.recalculateSize() to fully recompute child sizes
  • added a dedicated cached-child aggregation path for scan-time use so precomputed child sizes can be reused safely

Safety

This change is intentionally conservative. The new cleanup category targets only well-scoped, regenerated Xcode cache folders and does not include:

  • editor preferences
  • user settings
  • other persistent UserData content that may be expected to survive across Xcode launches

Performance notes

The scan optimization is deliberately isolated to the scan flow:

  • recalculateSize() still means “force recompute”
  • cached child sizes are reused only through a dedicated scan-time method

This preserves API clarity while improving scan time for both:

  • the new UserData Cache section
  • existing sections like Derived Data that precompute child sizes for sorting

Test plan

  • build the app with:
    • xcodebuild -project "DevCleaner.xcodeproj" -target "DevCleaner" -configuration Debug build
  • launch the app and verify a new UserData Cache section appears
  • confirm the section includes only:
    • SwiftUI previews
    • IB support simulator devices
    • capabilities cache
  • confirm scan completes successfully and sizes are shown
  • verify size-based ordering still works
  • verify scan time is improved compared with the initial UserData implementation
  • run CLI help/info and confirm user-data-cache appears as a supported clean target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant