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. Static build is slower than dynamic build
Forum Updated to NodeBB v4.3 + New Features

Static build is slower than dynamic build

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 832 Views 1 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.
  • P Offline
    P Offline
    Pedro-Beirao
    wrote on last edited by Pedro-Beirao
    #1

    So Ive compiled my app statically, but Im noticing slower startup times.
    Closing, then quickly opening the app has no noticable slowdown. This leads me to believe that it has something to do with some cache.

    I can reproduce this with an app as simple as a Hello World program

    Why is static slower?

    Im using QT6 on Windows btw

    jsulmJ 1 Reply Last reply
    0
    • P Pedro-Beirao

      So Ive compiled my app statically, but Im noticing slower startup times.
      Closing, then quickly opening the app has no noticable slowdown. This leads me to believe that it has something to do with some cache.

      I can reproduce this with an app as simple as a Hello World program

      Why is static slower?

      Im using QT6 on Windows btw

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

      @Pedro-Beirao said in Static build is slower than dynamic build:

      Why is static slower?

      I guess because the binary is bigger as it includes all dependencies in one file. So, the loader has to load a bigger binary.

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

      1 Reply Last reply
      3
      • P Offline
        P Offline
        Pedro-Beirao
        wrote on last edited by
        #3

        That makes sense, but I was hoping to know if anyone else experienced this. Maybe there is something wrong with my static Qt installation?

        jsulmJ 1 Reply Last reply
        0
        • P Pedro-Beirao

          That makes sense, but I was hoping to know if anyone else experienced this. Maybe there is something wrong with my static Qt installation?

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

          @Pedro-Beirao How long does it take actually? How big is the difference compared to shared libraries?

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

          1 Reply Last reply
          1
          • P Offline
            P Offline
            Pedro-Beirao
            wrote on last edited by
            #5

            Shared is instantaneous, while Static takes up to 5 seconds.
            This is a small app and being this slow is not an option

            jsulmJ W 2 Replies Last reply
            0
            • P Pedro-Beirao

              Shared is instantaneous, while Static takes up to 5 seconds.
              This is a small app and being this slow is not an option

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

              @Pedro-Beirao 5 seconds is indeed a lot for a small app. You could try to run your app through a profiler to see where it spends most time (provided it is not the OS loader consuming all that time).

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

              1 Reply Last reply
              2
              • P Offline
                P Offline
                Pedro-Beirao
                wrote on last edited by
                #7

                What profiler would you recommend?

                jsulmJ 1 Reply Last reply
                0
                • P Pedro-Beirao

                  What profiler would you recommend?

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

                  @Pedro-Beirao That depends on your OS and compiler.
                  For Linux see https://stackoverflow.com/questions/2497211/how-to-profile-multi-threaded-c-application-on-linux
                  For Microsoft compiler I don't know (I don't use them), but there should be a profiler.

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

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pedro-Beirao
                    wrote on last edited by
                    #9

                    Alright, thanks!

                    1 Reply Last reply
                    0
                    • P Pedro-Beirao

                      Shared is instantaneous, while Static takes up to 5 seconds.
                      This is a small app and being this slow is not an option

                      W Offline
                      W Offline
                      wrosecrans
                      wrote on last edited by
                      #10

                      @Pedro-Beirao What's that 5 seconds actually measuring? To start main() or 5 seconds after it gets to main() to show a UI? And how big is your binary? And how did you build? -- Is this a debug build or an optimized build? Does your compiler have Link Time Optimizations enabled?

                      1 Reply Last reply
                      1
                      • P Offline
                        P Offline
                        Pedro-Beirao
                        wrote on last edited by Pedro-Beirao
                        #11

                        Profiled with VerySleepy, and it takes 5 seconds to start main().
                        Final static binary is 20mb
                        Happens with both debug and release builds.
                        I use Qmake and Mingw to compile and haven't enabled any LTO

                        VerySleepy shows that the funtion ZwWaitLowEventPair from ntdll is the culprit of the slowdown, but I didnt find anything about it online

                        What LTO should I use?

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Pedro-Beirao
                          wrote on last edited by
                          #12

                          Compiled Qt statically with -static-runtime enabled, and now the slowdown is gone.
                          Maybe finding libstdc++ and libgcc was slow.

                          I'll still need to do some more testing, but Im positive that this was the problem

                          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 Extensions
                          • Unsolved