Laggy, frozen, slow Mojave: 100% consistent methods to reproduce, discussion of possible cause, and proposed user workarounds
This is a followup to my post from 6 Oct 2018 here:
The full description of symptoms is there, including attempted fixes and workarounds. Briefly, if you're reading this, it's because your Mojave install keeps freezing all the time, and you've come here to find out why, and what you can do about it.
Here's what I've discovered, and some ways you might work around it. Tl;dr: Leave your system plugged in and powered on to your user desktop for a weekend.
Seriously.
Reproducing the error
In bugfixing, consistency is important. Reliably reproducing an error is a major step in finding the cause, and addressing it. I've been able to reliably and consistently bog, then freeze, my Mac by two separate user-initiated methods:
1. Attempt to copy a corrupted file. The copy op lags, then halts, while the Mac slows, then freezes. Eventually, Finder throws a (-36) error, and normal system operation resumes, after a delay.
2. Attempt to compress a corrupted file, using the "Compress" command from the popup menu (right/ctrl-click the file). Compression begins, but at some point in the process, it lags and halts, while the Mac slows, then freezes. In this case, for me, I get no error message; simply an empty and nondismissable window where once there was a progress bar:
Oops.
Activity Monitor never indicates there is a runaway process. The only evidence the user has of any problem is the increasing lack of system responsiveness, culminating by a freeze in all UI elements, which eventually clears after the copy/zip operation aborts.
Likely cause of the laggy/slow/frozen Mojave error
I believe Mojave, when it begins copying a file, does what you'd expect it to do: It reads data, then writes it. However, some files may be fragmented, some substantially so; chasing down those fragments takes a while.
I think while it's copying, Mojave may be attempting to defrag the source file at the same time. In some cases, this could result in system lagginess.
In some cases, the file may actually be damaged. So Mojave begins looking for the missing pieces, and may be looking all over the source volume to find them. Eventually, it's scanned everywhere it can look, is unable to locate the missing pieces, and returns a (-36) error.
During the time it's conducting its search of the hard drive for the file data, the file I/O process is seizing processor and disk-read/write resources, effectively freezing the rest of the system until it surrenders control of the hardware.
If this is a low-level file I/O issue, it would manifest on both SSD and rotational (hard) disk drives. It would take longer to clear or resolve on HDD's, but it would definitely happen on everything, regardless of the underlying disk drive hardware.
And particularly if you have a lot of files, the freeze is likely to go on longer, and take more time to unfreeze, because that file I/O process is searching everywhere there's data for those missing pieces.
And because this is very probably a macOS Mojave error, it doesn't matter if your machine is only a few months old, or if you've had it for years. All it takes is some fragmented or corrupted files, and particularly on older legacy installs, you bet you have a few of both on your drive.
If my surmise is correct, this will happen even on SSD based machines that are upgrading from High Sierra (they had APFS before Mojave; APFS only came to fusion and rotational drives with 14.0), because it's a fault in Mojave's file I/O, not one found in High Sierra.
What does this have to do with me? I'm not copying files. I'm just trying to use my Mac!
You wouldn't think reading a web page or replying to an email would be enough to kill your entire computer for minutes at a time, and you're right; it's not.
But in the background, Spotlight is indexing and rebuilding its database, which is a normal function after a new system install.
Also in the background, macOS is defragmenting files.
And particularly after a new install, there's a lot of file moving and cleanup going on.
These processes are all attempting to read and write data from files, and are very probably using exactly the same subprocess as copying files, or compressing them.
Which would mean macOS is doing the same thing, trying to defrag or repair files on the fly, in the background, while you're reading a website or replying to an email. And suddenly, bam, your system is frozen for no good reason you can see.
Great. So what can I do about it?
Not a heck of a lot. There are two things you can do that might help.
1. Turn off Spotlight indexing for your entire disk. This will substantially reduce the amount of file read/write happening in the background. To do that:
a. Select the Spotlight pane in System Preferences.
b. Click the "Privacy" tab.
c. Add your hard drive there, either by dragging/dropping it, or clicking the "+" button and selecting it from the file window. Add the entire drive. By default it's named "Macintosh HD", but it'll be something else, if you've subsequently renamed it.
Spotlight will warn you that "some" search functions won't work. Sigh, and click OK. That's true; a lot of search functions won't work, if Spotlight is not indexing your drive. Stay with me, though, because you don't necessarily have to keep it turned off until the 14.1 update.
2. After you've logged in to your desktop, disable all sleep functions (Energy Saver settings that shut off the disk after a while, or sleep the system, etc), leave your Mac logged in and powered up, and plug it in if it's a portable.
Then walk away from it for a day or two.
This isn't an ideal suggestion if it's your only computer, I know.
What this should do is let Mojave resolve its issues on its own. You won't notice lags or hangs if you're not paying attention to the computer at all.
After a day or two, try doing stuff on your Mac and see if it's behaving normally. If it is, turn Spotlight indexing back on, then walk away again for a couple of days.
When the #311 will this be fixed?
Very probably with 14.1. If you still have a backup of High Sierra, you might be able to roll back to that, but it's not likely to go much faster, really, than just walking away from the Mac for a couple days until those fragmented/corrupted files have been dealt with by the OS's background processes.
Well how do you know it works to "just walk away", huh?
I'm writing and posting this from exactly the same Mini I reported all these problems on, two days ago, as described in my original post, linked above.
There are still a few lags and bogs, but they've dropped off significantly since I left this Mini powered up overnight, while I've been copying files from my home folder to an external drive, and deleting the ones Finder throws a (-36) on.
You may be able to expedite this process yourself by doing what I've been doing: Copy each subfolder in your home folder to an external HD. Whenever Finder throws a (-36) error on a file, locate that file and delete it. But it's not a lot of fun.
macOS Mojave (10.14)