perf(clean): replace file-based mdfind cache with in-memory lookups#986
Merged
Merged
Conversation
The orphan scan forked grep twice per candidate to check the mdfind cache file. On machines with 200+ items in ~/Library/Caches this added 400+ subprocess forks purely for cache hits. Replace the temp-file cache with newline-delimited bash variables checked via case glob matching (zero forks, bash 3.2 compatible). Unify three separate caches into one shared store so bundle IDs resolved during orphan scanning are not re-queried during system service or container stub scanning. Add caching to _container_stub_app_exists which previously had none. Isolated benchmark: ~15x faster cache lookups (539ms → 33ms for 200 bundle IDs). End-to-end mo clean impact is marginal (~1% of total runtime) since mdfind queries and filesystem traversal dominate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
grep -Fxqsubprocess forks on a temp file with in-memory newline-delimited string variables checked viacaseglob matching (bash 3.2 compatible, zero forks per lookup)is_bundle_orphaned,is_claude_vm_bundle_orphaned,_system_service_app_exists) into one shared store, so a bundle resolved in one phase is not re-queried in another_container_stub_app_existswhich previously had noneBenchmark
Isolated cache lookup (median of 5 runs, bash 3.2, Apple Silicon):
End-to-end
mo clean --dry-run: no perceptible difference (~41s both). Cache lookups are ~1% of total runtime; the win is fewer fork/exec calls and shared cache across scan phases.Test plan
MOLE_TEST_NO_AUTH=1 bats tests/clean_apps.bats(25/25)MOLE_TEST_NO_AUTH=1 bats tests/uninstall_safety.bats(13/13)MOLE_TEST_NO_AUTH=1 bats tests/bundle_resolver.bats(11/11)bash -non alllib/clean/*.sh