Incredibly slow moc - any gotchas I should be aware of?
-
I'm using Qt 5.6.2 on a project (for compatibility reasons) and the moc is taking 5+ minutes PER header file (and I have hundreds of headers which contain different qt classes, so the moc alone takes hours to run). Thankfully I don't have to recompile the project often, but this is still unbelievably and unbearably slow.
Surely there must be an explanation for the slow compile time....the headers themselves are nominal in size and the resulting moc*.cpp files are less than 100 lines long...so what the moc is actually wasting all this time doing is a mystery. The task manager shows moc.exe processes running at 0-1% CPU usage during compilation, with steadily increasing RAM usage.
The project contains a lot of different dependencies and so it's not easy for me to reproduce the issue in a vacuum or post the code. So, barring any specifics, are there any moc 'gotchas' that I should be aware of, which could be the culprit? Things which could dramatically increase moc time in some cases? Or is there some other way to debug what the moc is spinning its wheels on?
-
Hi,
Is your code base stored locally ?
If so, what kind of disk is that ?
Are you including lots of headers in these headers ?
Do your dependencies do that ? -
Yes, locally on an SSD. I don't think read/write is the issue.
I don't have a ton of header includes but perhaps there's some nested expansion in one of my dependencies that's causing the issue...I'm trying to pair things down and remove everything from the headers that isn't completely necessary to the Qt class definitions. But still....the entire project which contains thousands of non-moc'd headers compiles nearly an order of magnitude faster than it takes for the moc to run and generate a couple hundred 4kb files. Does the moc run considerably faster in newer versions of Qt?
-
Having minimal includes is always better. Everything that you can forward declare should be.
I never had performance issues with moc so I can't tell whether newer versions would be faster but I doubt it in the sense that moc does a single job and has not changed much to the best of my knowledge.
Do you have macros in your headers ?
-
I have macros, yes. Do they not play well with the moc?
-
moc used to not expand them and if memory serves well it started with Qt 5 so I wonder if there's something going on with that.
-
I still would guess it's a include problem - I've a similar problem in one of my projects at work where a lot of includes are in the headers which slows down moc, esp. on windows.
-
There was a thread on the Qt mailing list about that matter. One of the issue was also the way the included were done. Lots of headers within the same directory. Moving them to a separate folder and using specific "path/include.h" helped one that front as well.