This provides a PoC/WIP patch that shows a possible way to improve the current inefficiency in the dirwatching approach. That current approach consists of calling KDirWatch::addDir(<project source dir>) with the instruction to add all files and directories recursively.
This happens on the main thread and atomically, thus blocking the event loop for large projects. See D7742 for timing examples, and D7745 for a companion patch that adds temporary code for project import timing.
This patch installs watchers only on directories, and "online" during the import process itself, by FileManagerListJob. It still contains a bit of code allowing to turn off dirwatching; please note that this is only to allow evaluating the overhead of this new approach.
There's a mutex acting as a barrier to serialise access to the underlying QFileSystemWatcher object used by KDirWatch (when it uses QFSW); this change can of course be proposed upstream. It seems to be required despite Qt's claim that the class is reentrant. On Mac import times can be longer without it and on Linux I've seen sporadic memory allocation (and freeing) errors without it.