Skip to content

Blockchainpreneur/mac-perf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

mac-perf

On-demand macOS performance cleanup CLI. Pure bash, no dependencies.

Diagnose RAM/swap/load, kill stale dev servers, clear regenerable caches. Built for developers whose Mac is slow because they have 47 Chrome tabs, 6 zombie next dev processes, and 5 GB of cache nobody asked for.

Install

curl -sL https://raw.githubusercontent.com/Blockchainpreneur/mac-perf/main/mac-perf.sh \
  -o /usr/local/bin/mac-perf && chmod +x /usr/local/bin/mac-perf

Or clone and symlink:

git clone https://github.com/Blockchainpreneur/mac-perf.git
ln -s "$PWD/mac-perf/mac-perf.sh" /usr/local/bin/mac-perf

Usage

mac-perf                  # report (default — no kills, no deletions)
mac-perf clean            # safe cleanup, asks confirmation
mac-perf clean --yes      # safe cleanup, no prompt
mac-perf aggressive -y    # also kill hot dev servers + sudo purge

What it does

report (default)

Diagnoses your machine. Reports:

  • Uptime, load average, available RAM, swap usage, process counts
  • Stale dev serversnext dev / vite / webpack / nodemon running >2h
  • Hot dev servers — same, but using >50% CPU
  • Orphansgit fsmonitor, caffeinate reparented to PID 1
  • Duplicate workers — keeps newest 2 per pattern (MCP servers, devtools)
  • Cleanable caches — Chrome, npm, bun, Xcode, logs, etc. (above threshold)
  • Recommendations — reboot if uptime >14d, warn on swap thrashing

clean (safe)

  • Kills only stale dev servers (>2h elapsed)
  • Kills orphans + duplicate workers
  • Clears caches that auto-regenerate (npm, bun, ~/.cache, Logs)
  • Skips Chrome Service Worker cache if Chrome is running (would log you out)
  • Asks confirmation per destructive step unless --yes

aggressive

  • Everything in clean plus:
  • Kills hot dev servers (>50% CPU regardless of age)
  • Clears Chrome SW cache even if Chrome is running
  • Runs sudo purge to force-release inactive memory (requires NOPASSWD for /usr/sbin/purge)

Sample output

╔══════════════════════════════════════════════════════════╗
║              MAC-PERF REPORT                              ║
╚══════════════════════════════════════════════════════════╝

▸ System
    Uptime:     53 days
    Load avg:   11.77
    Avail RAM:  1.1G
    Swap used:  12.9G / 13.3G
    Procs:      513 (node:27, chrome:57)

▸ Stale dev servers (>2h elapsed)
    PID 96702  9942m  next-server (v16.2.2)
    PID 28038  1656m  next dev --port 3001

▸ Cleanable caches
    chrome-cache    1.5G
    chrome-sw       2.0G
    npm-cache       880M
    bun-cache       1.2G
    user-cache      332M
    logs            74M
    ───────────────────────
    TOTAL           5.9G

▸ Recommendations
    ⚠  Reboot recommended (uptime 53d, swap accumulates)
    ⚠  Swap thrashing (97%)
    ⚠  Process count high (513)

Why not just buy more RAM

You probably should. But until then, this script reliably reclaims 3-5 GB of disk and 500 MB-1 GB of RAM on a typical developer machine. The biggest single fix it can't do is reboot — swap doesn't release until you restart.

Safety

  • Default mode (report) never kills or deletes anything.
  • clean mode asks confirmation per step unless --yes.
  • Won't touch dev servers <2h old in safe mode (preserves active work).
  • Won't clear Chrome SW cache if Chrome is running unless aggressive.
  • All caches cleared are auto-regenerable (no data loss).
  • All kill operations send SIGTERM first, then SIGKILL only if the process refuses.

Configuration

Env var Default Purpose
MAC_PERF_LOG ~/.mac-perf.log Log file path
MAC_PERF_PAGE_SIZE 16384 Set to 4096 on Intel Macs

Optional: run on a schedule

The script is idempotent and safe to cron. Example LaunchAgent (~/Library/LaunchAgents/com.user.mac-perf.plist):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key><string>com.user.mac-perf</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/mac-perf</string>
        <string>clean</string>
        <string>--yes</string>
        <string>--quiet</string>
    </array>
    <key>StartInterval</key><integer>1800</integer>
    <key>RunAtLoad</key><false/>
</dict>
</plist>

Load it with launchctl load ~/Library/LaunchAgents/com.user.mac-perf.plist.

License

MIT — see LICENSE.

About

On-demand macOS performance cleanup CLI — diagnose RAM/swap/load, kill stale dev servers, clear regenerable caches. Pure bash, no dependencies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages