Edit In response to Tetsujin's comment, further details now are provided for reproducing the slowdown, and for reverting back to normal speed.
The usual caveat Experimenting with system-level bugs is inherently risky. You are advised not to do so, unless you have a working understanding of users, groups, and permissions and you possess reliable system backups.
Here's a "weird trick" that instantly makes my MacBook Pro / Yosemite system run slow slow slow ... create a circular group inclusion in the Users & Groups pane of System Preferences.
Answers Sought Why does this slowdown happen? Are other users affected? Is there a tool that automatically diagnoses and fixes it? How can it be avoided in the future?
Remark After creating this slowdown inadvertently, it took me two weeks to figure out, reproduce, and repair the cause of it. The search for a fix was slow and frustrating because none of the usual fixes of "slow Mac syndrome" were effective, and none of the usual diagnostics were revealing.
Reproducing the slowdown
In the System Preferences pane "Users & Groups"
- create new groups "a" and "b"
Close System Preferences.
Now open the Finder's "Get Info" pane for the directory at the base of a large directory tree ... for me /usr/local is large enough to elicit a severe slowdown. Then
- under "Sharing & Permissions", give "a", but not "b", read/write privileges to all files in the tree, via the menu-selected option "apply to enclosed items".
Now reopen the System Preferences pane "Users & Groups"
- include group "a" in group "b"
- include group "b" in group "a"
Voila! Now everything on my MacBook runs slow ... slow ... slow. Logins require up to one minute, and even simple typing sporadically elicits the "spinning pizza." Fortunately, eliminating the circular group inclusion instantly restores the system to its former speed.
Returning to normal speed
To revert the changes, reverse the above steps
- first undo the group "a" and group "b" circular inclusions
- then remove the group "a" read/write permissions
- then delete groups "a" and "b"
Hypothesis Yosemite's bash shell performs poorly in resolving circular group references when searching large directory trees in "$PATH" variables.
Evidence Even simple command-lines like "ls" run slowly ... it appears that when circular group inclusions are present, bash is slow in searching $PATH to locate the "ls" file.
System Software Overview:
System Version: OS X 10.10.2 (14C109)
Kernel Version: Darwin 14.1.0
Boot Volume: Macintosh HD
Boot Mode: Normal
Computer Name: [redacted]
User Name: [redacted] (Administration)
Secure Virtual Memory: Enabled
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro11,3
Processor Name: Intel Core i7
Processor Speed: 2.5 GHz
Number of Processors: 1
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 6 MB
Memory: 16 GB
Boot ROM Version: MBP112.0138.B14
Note also that /usr/local tree is fairly large (as is typical of developers and LaTeX users) ...
$ find /usr/local -type f | wc -l
204713