diff options
| author | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2022-03-23 09:33:22 +0100 |
|---|---|---|
| committer | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2022-04-11 10:50:27 +0200 |
| commit | a88f7b21c61e4aa9efcfb81d7939e44b06df3a0d (patch) | |
| tree | e0b9f6fd7b6f4cca40aab7f241d9ae4a16d2cca4 /sources/pyside6/cmake/PySideHelpers.cmake | |
| parent | 1049b1ed57e3ec591ddb5ebda1b501a102f95019 (diff) | |
PySide6: Optimize for Size
build: use the following flag with setup.py to turn off size optimization
--no-size-optimization
Added the following compiler optimization flags and their corresponding flags on
other platforms
GCC
- -ffunction-sections -fdata-section which segretates data and function section
and linker flag --gc-section which removes unused code.
- -fno-exceptions to disable exception handling
- -Os - Optimize for size. Basically same as -O2 but removes some flags that
cause increase in size. (Ran a couple of example and did not see difference in
execution time)
MSVC
- /Gy /Gw /OPT:REF - same as -ffunction-sections, -fdata-section, -Wl,
--gc-section
- /EHsc same as -fno-exceptions
- /O1 instead of /Os because for MSVC /O1 gave the best results.
Clang
- Same as GCC except for using -Oz instead of -Os.
Experiments:
Built a wheel with QtCore and noticed a 300kb reduction in size on both
Windows and Linux.
Built a complete wheel(except QTest) and it gives me a 4 mb size reduction
with unaffected performance.
Task-number: PYSIDE-1860
Change-Id: Ia5dfa2c4bfde92994c939b5fac0d0831fa3a73ab
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/cmake/PySideHelpers.cmake')
| -rw-r--r-- | sources/pyside6/cmake/PySideHelpers.cmake | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sources/pyside6/cmake/PySideHelpers.cmake b/sources/pyside6/cmake/PySideHelpers.cmake index 86cda83f8..0de8e1bdc 100644 --- a/sources/pyside6/cmake/PySideHelpers.cmake +++ b/sources/pyside6/cmake/PySideHelpers.cmake @@ -252,3 +252,16 @@ macro(collect_module_if_found shortname) endif() endif() endmacro() + +# resets the RELEASE CXX flags for size based optimization +macro(override_release_flags_for_size_optimization) + if(NOT QFP_NO_OVERRIDE_OPTIMIZATION_FLAGS) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(CMAKE_CXX_FLAGS_RELEASE "/O1 /DNDEBUG") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG") + elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG") + endif() + endif() +endmacro() |
