Qt application size optimization
-
wrote on 15 Sept 2022, 05:11 last edited by RAJEESHR
Hi All,
we have a Qt application(UI written using widgets, not qml) which sizes more than 40mb. And also we have total ~1mb of image files which are now compiled into binary. In the hardware (specific h/w having limitation on memory) it took some time(~20sec) to load into the memory and showed up the first screen. Now we are trying to reduce the size of the application through maximum feasible ways. We thought of moving some part as a library which can be loaded separately on demand and other application optimization to reduce the boot time. Now my question to all Qt experts here is,
From Qt perspective what all things I can try to reduce the Qt application?
Is there any guideline/example link is there?
-ltcg option is available with Qt5.7?Please help me. any help appreciated. Thanks in advance.
-
wrote on 15 Sept 2022, 06:15 last edited by
Platform? Compiler tools?
Have you built a release executable? -
wrote on 19 Sept 2022, 02:12 last edited by
OS: ubuntu
compiling from Qt creator -
wrote on 19 Sept 2022, 04:34 last edited by
@RAJEESHR said in Qt application size optimization:
From Qt perspective what all things I can try to reduce the Qt application?
A single 40MB executable is a bit of a monster in the first place. It is going to take quite a while to load regardless of platform.
Since we have no idea what the structure is, it hard to say where to cut.
Make sure you are building a release executable. Debug executables are substantially larger.
Since you are using GCC you can try the space optimisation compiler option (-Os
) rather than the-O2
or-O3
default.
Profile your code to see where it spend the most time during startup, then concentrate of those areas.It may be that the load time is actually a slow embedded processor loading and linking a huge file and libraries from a slow storage. Depending on which is the biggest bottleneck then an executable compression like UPX may help (you trade decompression time for file size).
It may be that the load is constrained by memory and the machine is swapping. This will impact performance across the board.
Is there any guideline/example link is there?
No general guide is going to address your specific program on your target platform.
-ltcg option is available with Qt5.7?
No. Qt is a library and this is an option is for a compiler and/or linker.
You are talking about a Microsoft compiler option so, no, it does not exist in your Ubuntu GCC tools. The rough equivalent would seem to be the
-flto
option. Please read the documentation because this option imposes a lot of conditions. I doubt this is going to massively improve much. -
Hi,
One thing you can also explore is the Qt feature system that allows you to disable quite a lot of features you don't use thus reducing the library and your application size.
-
You should also run strip on your binary.
1/6