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. Statically build program is slower.
QtWS25 Last Chance

Statically build program is slower.

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 1.7k Views
  • 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.
  • S Offline
    S Offline
    samdol
    wrote on last edited by
    #1

    Hi,
    I have compiled my application dynamically and statically using Qt 5.6.2 under
    windows 7. Running speed seems similar. But when I start the program, program loading speed seems different as following,
    Dynamic: 1.6 second
    Static: 2.2 second
    So statically build program feels heavier to start. I thought, because static build has smaller files size, it must be faster to load.

    I copy the program to windows 10 machine, the difference is more clear
    Dynamic: 1.4 second
    Static: 5.5 second

    I don't understand why it takes too long to start statically build program in
    windows 10. Do I have to compile statically under windows 10 to make it faster
    to start?

    .pro file loos like
    QT += multimedia
    QT += svg
    qtHaveModule(printsupport): QT += printsupport
    and it includes 2 external library files

    aha_1980A JonBJ 2 Replies Last reply
    0
    • S samdol

      Hi,
      I have compiled my application dynamically and statically using Qt 5.6.2 under
      windows 7. Running speed seems similar. But when I start the program, program loading speed seems different as following,
      Dynamic: 1.6 second
      Static: 2.2 second
      So statically build program feels heavier to start. I thought, because static build has smaller files size, it must be faster to load.

      I copy the program to windows 10 machine, the difference is more clear
      Dynamic: 1.4 second
      Static: 5.5 second

      I don't understand why it takes too long to start statically build program in
      windows 10. Do I have to compile statically under windows 10 to make it faster
      to start?

      .pro file loos like
      QT += multimedia
      QT += svg
      qtHaveModule(printsupport): QT += printsupport
      and it includes 2 external library files

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @samdol

      So statically build program feels heavier to start.

      yeah, sure, because now all code has to be loaded at startup. on dynamic linking, the library code loading can be delayed, in worst case until the library functions are use first..

      i don't think compiling on W10 will make a difference. CPU, RAM and HD speed will.

      Qt has to stay free or it will die.

      S 1 Reply Last reply
      3
      • aha_1980A aha_1980

        Hi @samdol

        So statically build program feels heavier to start.

        yeah, sure, because now all code has to be loaded at startup. on dynamic linking, the library code loading can be delayed, in worst case until the library functions are use first..

        i don't think compiling on W10 will make a difference. CPU, RAM and HD speed will.

        S Offline
        S Offline
        samdol
        wrote on last edited by samdol
        #3

        @aha_1980
        Does that mean it is almost always better to compile dynamically as far as concerning loading time?
        So may I summarize pros/cons as following?
        Dynamic : faster launching speed, but large number of files taking big disk space.
        Static : Single executable smaller size file, but slower launching speed.

        Is there any other advantages to compile statically?

        W 1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          The biggest advantages (IMHO) from static linking is the single exe. There are no external
          dependencies that must be included , nor is it possible to crash due to wrong/unexpected version of a DLL/so file. You are also less prone to injection attacks and the the whole maintenance complexity is reduced.

          S 1 Reply Last reply
          5
          • S samdol

            @aha_1980
            Does that mean it is almost always better to compile dynamically as far as concerning loading time?
            So may I summarize pros/cons as following?
            Dynamic : faster launching speed, but large number of files taking big disk space.
            Static : Single executable smaller size file, but slower launching speed.

            Is there any other advantages to compile statically?

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

            @samdol If you have many programs using the libraries, dynamic libraries will be much smaller in aggregate than a bunch of individual static binaries all carrying around a copy of the library. Static binaries are really only likely to be smaller when you only consider the case of a single binary that has unused functionality stripped out. As soon as you have multiple binaries sharing the library, or the binary links to all the functions of the library, it's not a benefit.

            There's a reason people invented shared libraries, you know!

            1 Reply Last reply
            4
            • S samdol

              Hi,
              I have compiled my application dynamically and statically using Qt 5.6.2 under
              windows 7. Running speed seems similar. But when I start the program, program loading speed seems different as following,
              Dynamic: 1.6 second
              Static: 2.2 second
              So statically build program feels heavier to start. I thought, because static build has smaller files size, it must be faster to load.

              I copy the program to windows 10 machine, the difference is more clear
              Dynamic: 1.4 second
              Static: 5.5 second

              I don't understand why it takes too long to start statically build program in
              windows 10. Do I have to compile statically under windows 10 to make it faster
              to start?

              .pro file loos like
              QT += multimedia
              QT += svg
              qtHaveModule(printsupport): QT += printsupport
              and it includes 2 external library files

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @samdol
              Unless you have a very good reason, you always want dynamic not static libraries. If you mean the Qt was static/dynamic as well as other libraries, then not to mention, if you have any intention of distributing the Qt application you are building, and you want to be free...!

              1 Reply Last reply
              2
              • mrjjM mrjj

                Hi
                The biggest advantages (IMHO) from static linking is the single exe. There are no external
                dependencies that must be included , nor is it possible to crash due to wrong/unexpected version of a DLL/so file. You are also less prone to injection attacks and the the whole maintenance complexity is reduced.

                S Offline
                S Offline
                samdol
                wrote on last edited by samdol
                #7

                @mrjj
                I read some comments in other sites, some say static binary is faster than dynamic binary for launching because it does not need to look for library files. Beside, even with all those advantages, from the end user's point of view, if the static binary(5.5 sec) is considerably slower than dynamic binary (1.4 sec) in launching, there seems no point to purchasing license for static compile. I still don't understand why my static app is considerably slower than dynamic app in windows 10.

                aha_1980A W 2 Replies Last reply
                0
                • S samdol

                  @mrjj
                  I read some comments in other sites, some say static binary is faster than dynamic binary for launching because it does not need to look for library files. Beside, even with all those advantages, from the end user's point of view, if the static binary(5.5 sec) is considerably slower than dynamic binary (1.4 sec) in launching, there seems no point to purchasing license for static compile. I still don't understand why my static app is considerably slower than dynamic app in windows 10.

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @samdol are the computers comparable otherwise? (CPU, RAM, HDD)?

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  0
                  • S samdol

                    @mrjj
                    I read some comments in other sites, some say static binary is faster than dynamic binary for launching because it does not need to look for library files. Beside, even with all those advantages, from the end user's point of view, if the static binary(5.5 sec) is considerably slower than dynamic binary (1.4 sec) in launching, there seems no point to purchasing license for static compile. I still don't understand why my static app is considerably slower than dynamic app in windows 10.

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

                    I read some comments in other sites, some say static binary is faster than dynamic binary for launching because it does not need to look for library files.

                    @samdol How large is the search path for the libraries? If some commenters on the Internet say static binaries are faster and your stopwatch says they aren't, which will you believe?

                    On Linux, you can use something like strace and fiddle with LD_LIBRARY_PATH to measure how long the search process takes as you add additional candidate directories . Hint: in general it's not very large. If it wasn't, systems wouldn't use dynamic libraries so much. If the libraries are already in memory (because shared) then it's just coming out of page cache and the filesystem overhead to get to the code in the libraries will be small.

                    I still don't understand why my static app is considerably slower than dynamic app in windows 10.

                    It's much larger, for starters. Past that, use a profiler! Measure it! Random strangers on the internet can't possibly know more about what your computer is doing with your code than you can!

                    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