Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-98894

Make the binary smaller on Windows

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • Build System
    • None
    • Windows

      We can make MSVC produce smaller binary by passing some specific parameters to it.

      Possible choices:

      /O1: optimize for size. Will be enabled if pass -DFEATURE_optimize_size=ON when configuring Qt. TESTED. Can reduce the binary size quite some bit.

      /Ob1: lower inline code expansion level. TESTED. Can reduce the binary size in some degree. Better use it together with /O1.

      /Gy + /Zc:inline + /OPT:REF + /OPT:ICF: eliminate dead code. Qt's default since long time ago. /Gy will be implied by /O1 and /O2.

      /Gw: optimize global data. TESTED. Can reduce the binary size indeed, but not very much.

      /GL + /LTCG: enable whole program optimization / link time code generation. TESTED. Sometimes the binary size becomes smaller, sometimes larger, not sure the exact condition.

      /GR-: disable runtime type information (RTTI) generation. TESTED. Can reduce the binary size in some degree, but sadly some Qt modules depend on this feature so we can't disable RTTI unconditionally.

      /EHs-c-: disable C++ exception handling. TESTED. Can reduce the binary size quite some bit.

      /EHsc + /d2FH4: enable C++ exception handling but use the new exception handling model introduced in VS2019. In theory it will be much smaller than the traditional exception handling model. The binary size will become much smaller if the code makes heavy usage of exception handling, such as Microsoft's WinUI library.

        1. size compare-dev-c6c039.png
          127 kB
          赵 宇航
        2. size compare-dev-c6c039.xlsx
          15 kB
          赵 宇航
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtbuildsystem Qt Build System Team
            wangwenx190 赵 宇航
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes