Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reduce compilation time
Forum Updated to NodeBB v4.3 + New Features

Reduce compilation time

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 3.6k 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.
  • M Offline
    M Offline
    Massimiliano75
    wrote on last edited by
    #1

    I have a big project, compilation time six minutes, to reduce the time I am trying to put #include "moc_file.cpp" inside the "file.cpp" (the other things I have already tried), is this a good idea?

    J.HilkJ 1 Reply Last reply
    1
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      How would that speed up anything?

      the other things I have already tried

      What have you tried, specifically?

      Some things I know:

      • don't do full rebuilds unless you have to - make use of incremental builds
      • use forward declarations as much as possible and everywhere (it can speed things up by even 30-40%)
      • only include what you use (no #include <QtGui> etc.)
      • use precompiled headers
      • use a fast build system (qbs or cmake+ninja, not qmake)
      • this is debatable (I don't really recommend it), but you can try lowering the number of build synchronization steps - by reducing number of libraries you compile. Linking libraries cannot be parallelised
      • use ccache - it can potentially speed things up by even 90+%
      • if you have more PCs, you can also use distcc or some other distributed compilation technology
      • buy a new PC :D New CPUs have crazy core counts, and when coupled with fast SSD drives compilation times go way down

      (Z(:^

      1 Reply Last reply
      4
      • M Massimiliano75

        I have a big project, compilation time six minutes, to reduce the time I am trying to put #include "moc_file.cpp" inside the "file.cpp" (the other things I have already tried), is this a good idea?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Massimiliano75
        in addition to the excellent points of @sierdzio
        A few qt related things,

        If you use QtCreator, are you sure make is called with the multi core option (thats not the default on Windows)

        do you have a sub dir project and you're using the forbidden ordered option?

        What compiler are you using? There may be a more optimized one for the OS you're targeting

        Where do your files live ? Hopefully not on network path but a local ssd or even ram-drive

        Did you make sure to exclude your build folder from your anti virus software ? I have a very invasive Antivirus that I'm forced to use and its taking a whole cpu core to check all files in the build folder while they are being build slower down my build significantly


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3
        • M Offline
          M Offline
          Massimiliano75
          wrote on last edited by
          #4

          I've already done:

          1. don't do full rebuilds unless you have to - make use of incremental builds
            ok I would like to reduce the time of full compilation because we often change development branches
          2. i use precompiled headers
          3. i use forward declarations
          4. i use parallel compilation - j option
          1 Reply Last reply
          0
          • M Offline
            M Offline
            Massimiliano75
            wrote on last edited by
            #5

            @J-Hilk said in Reduce compilation time:

            If you use QtCreator, are you sure make is called with the multi core option (thats not the default on Windows)
            Yes , i work under linux and i monitor the cpu

            do you have a sub dir project and you're using the forbidden ordered option?
            i have four subdir, but i don't use the forbidden ordered option
            What compiler are you using? There may be a more optimized one for the OS you're targeting
            linux , gcc x86 64bit
            Where do your files live ? Hopefully not on network path but a local ssd or even ram-drive
            ssd
            Did you make sure to exclude your build folder from your anti virus software ? I have a very invasive Antivirus that I'm forced to use and its taking a whole cpu core to check all files in the build folder while they are being build slower down my build significantly
            no antivirus

            With #include "moc_file.cpp" inside the "file.cpp" I am reducing the time

            sierdzioS 1 Reply Last reply
            1
            • M Massimiliano75

              @J-Hilk said in Reduce compilation time:

              If you use QtCreator, are you sure make is called with the multi core option (thats not the default on Windows)
              Yes , i work under linux and i monitor the cpu

              do you have a sub dir project and you're using the forbidden ordered option?
              i have four subdir, but i don't use the forbidden ordered option
              What compiler are you using? There may be a more optimized one for the OS you're targeting
              linux , gcc x86 64bit
              Where do your files live ? Hopefully not on network path but a local ssd or even ram-drive
              ssd
              Did you make sure to exclude your build folder from your anti virus software ? I have a very invasive Antivirus that I'm forced to use and its taking a whole cpu core to check all files in the build folder while they are being build slower down my build significantly
              no antivirus

              With #include "moc_file.cpp" inside the "file.cpp" I am reducing the time

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @Massimiliano75 said in Reduce compilation time:

              With #include "moc_file.cpp" inside the "file.cpp" I am reducing the time

              Thanks, good to know!

              (Z(:^

              1 Reply Last reply
              1
              • KH-219DesignK Offline
                KH-219DesignK Offline
                KH-219Design
                wrote on last edited by JKSH
                #7

                @sierdzio said in Reduce compilation time:

                With #include "moc_file.cpp" inside the "file.cpp" I am reducing the time

                I am intrigued. Does anyone have an explanation for why/how this works? [Discussion forked to https://forum.qt.io/topic/117973/ --JKSH]

                Also, how/why did anyone even think of trying it? (The thought has never occurred to me.)

                On a separate note:

                The single most important tactic I have ever seen for reducing time of an incremental rebuild (not full build) is to clean up the header-to-header include graph. https://xania.org/200712/c-plus-plus-header-dependency-tricks

                Even though you mention switching development branches often, if the version control system and the build system are sane you should not have to do a full clean-and-rebuild just to switch branches. (Using git and a qmake build), I switch branches 10+ times per day and only do incremental rebuilds each time.

                www.219design.com
                Software | Electrical | Mechanical | Product Design

                JKSHJ 1 Reply Last reply
                4

                • Login

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