Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why is moc slow for some classes?
Qt 6.12 LTS is out! See what's new in the release blog

Why is moc slow for some classes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 6 Posters 6.4k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dan Princ

    @artwaw I have not measured, but the files that are slow are all similar and there are a few thousands other files on the project, which mostly take about 0.5-0.6 sec to parse, so it seems unlikely to be caused by I/O. (and obviously this is reproducible, it's not one time measurement)

    @J.Hilk It is a possibility I'm considering, but we still use some other features of metaObject(), so it would require a little more effort.

    artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #6

    @Dan-Princ Thanks for clarifying that. My next check would be internal includes, maybe there is a loop somewhere?
    Please note though that I never experienced that kind of problems before and perform a logical guess here.

    For more information please re-read.

    Kind Regards,
    Artur

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dan Princ
      wrote on last edited by
      #7

      Since I haven't figured out much more about this problem, I removed the Q_OBJECT macro from these classes. Not the best solution, but the only one I know of...

      mrjjM 1 Reply Last reply
      0
      • D Dan Princ

        Since I haven't figured out much more about this problem, I removed the Q_OBJECT macro from these classes. Not the best solution, but the only one I know of...

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #8

        @Dan-Princ

        Hi
        moc does not expand templates. its not a compiler.

        I tried a few combinations but I could not make moc hang/be slow on any files.

        Do you have a concrete example that compiles and is known to take extra time?

        D 1 Reply Last reply
        2
        • mrjjM mrjj

          @Dan-Princ

          Hi
          moc does not expand templates. its not a compiler.

          I tried a few combinations but I could not make moc hang/be slow on any files.

          Do you have a concrete example that compiles and is known to take extra time?

          D Offline
          D Offline
          Dan Princ
          wrote on last edited by
          #9

          @mrjj Unfortunately not, I can't share the code that does it and it's not happening if I try to create some minimal example...

          mrjjM jsulmJ 2 Replies Last reply
          0
          • D Dan Princ

            @mrjj Unfortunately not, I can't share the code that does it and it's not happening if I try to create some minimal example...

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            @Dan-Princ
            ok, i understand.

            I did try with some class with lots of base classes but saw no effect.

            Only by make extremely large .h file i could get time up but it sounds your case
            is different.

            1 Reply Last reply
            0
            • D Dan Princ

              @mrjj Unfortunately not, I can't share the code that does it and it's not happening if I try to create some minimal example...

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #11

              @Dan-Princ Just an idea: do you include many header files which include other header files and so on?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              1
              • jsulmJ jsulm

                @Dan-Princ Just an idea: do you include many header files which include other header files and so on?

                D Offline
                D Offline
                Dan Princ
                wrote on last edited by Dan Princ
                #12

                @jsulm Well if I compile the file with /showIncludes, it prints ~3800 includes (mostly from libraries - 2600 from boost, 500 from Qt). If I run preprocessor on the header file, it has about 780000 lines. But I don't know how relevant it is as these numbers will be similar for most of the files I think...

                kshegunovK 1 Reply Last reply
                0
                • D Dan Princ

                  @jsulm Well if I compile the file with /showIncludes, it prints ~3800 includes (mostly from libraries - 2600 from boost, 500 from Qt). If I run preprocessor on the header file, it has about 780000 lines. But I don't know how relevant it is as these numbers will be similar for most of the files I think...

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #13

                  @Dan-Princ said in Why is moc slow for some classes?:

                  • 2600 from boost

                  Boost is a template library (mostly) and as any template library is notorious for terrible compilation times, which is a consequence of how templates work.

                  it has about 780000 lines

                  And you have your answer. That's a huge file to parse.
                  And by the way, as @mrjj already said, you can't mix templates and QObject.

                  Read and abide by the Qt Code of Conduct

                  D 1 Reply Last reply
                  1
                  • kshegunovK kshegunov

                    @Dan-Princ said in Why is moc slow for some classes?:

                    • 2600 from boost

                    Boost is a template library (mostly) and as any template library is notorious for terrible compilation times, which is a consequence of how templates work.

                    it has about 780000 lines

                    And you have your answer. That's a huge file to parse.
                    And by the way, as @mrjj already said, you can't mix templates and QObject.

                    D Offline
                    D Offline
                    Dan Princ
                    wrote on last edited by
                    #14

                    @kshegunov That's a huge file to parse, true, but there are many other files that have similar (500000) number of lines after preprocessor and moc takes 0.6sec. So I'm not sure this is the main factor.

                    You can't put Q_OBJECT inside a template, but AFAIK you can have templated base class.

                    kshegunovK 1 Reply Last reply
                    0
                    • D Dan Princ

                      @kshegunov That's a huge file to parse, true, but there are many other files that have similar (500000) number of lines after preprocessor and moc takes 0.6sec. So I'm not sure this is the main factor.

                      You can't put Q_OBJECT inside a template, but AFAIK you can have templated base class.

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #15

                      @Dan-Princ said in Why is moc slow for some classes?:

                      You can't put Q_OBJECT inside a template, but AFAIK you can have templated base class.

                      Yes if it doesn't derive from QObject you can do something like:

                      class A : public QObject, public MyTemplatedClass< ... > //< QObject derived class always goes first!
                      {
                      };
                      

                      But even then it's rather clumsy. QObject doesn't play well with templates.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt
                      • Unsolved