Skip to content

Enable LTO on Linux anc Mac Release#639

Open
apaniukov wants to merge 2 commits intoopenvinotoolkit:masterfrom
apaniukov:reduce-binary-size-linux-mac
Open

Enable LTO on Linux anc Mac Release#639
apaniukov wants to merge 2 commits intoopenvinotoolkit:masterfrom
apaniukov:reduce-binary-size-linux-mac

Conversation

@apaniukov
Copy link
Copy Markdown
Collaborator

@apaniukov apaniukov commented Apr 7, 2026

Window binary is 2 times smaller then on other platforms. Enable LTO to reduce binary size on Linux and Mac.
From 7.9 Mb to 3.6 Mb on Linux.
From 7.9 Mb to 3.9 Mb on Mac (same as Windows)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables Link Time Optimization (LTO) for Release builds to reduce the size of the produced shared library on non-Windows platforms, aligning Linux/macOS output more closely with Windows size.

Changes:

  • Add -flto compile and link flags for Release builds in src/CMakeLists.txt.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/CMakeLists.txt
Comment thread src/CMakeLists.txt
Comment thread src/CMakeLists.txt
@apaniukov apaniukov requested a review from pavel-esir April 7, 2026 17:47
@apaniukov apaniukov marked this pull request as ready for review April 7, 2026 17:47
@apaniukov apaniukov requested a review from Copilot April 7, 2026 17:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CMakeLists.txt Outdated
Comment on lines +56 to +58
if(NOT MSVC)
include(CheckIPOSupported)
check_ipo_supported(RESULT ov_tokenizers_ipo_supported OUTPUT ov_tokenizers_ipo_error LANGUAGES C CXX)
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard if(NOT MSVC) enables IPO/LTO for any non-MSVC toolchain, including Windows MinGW builds. This doesn’t match the PR’s stated intent (“Linux and Mac Release”) and may unexpectedly change Windows/non-MSVC builds. Consider tightening the condition to Linux/macOS only (e.g., using the LINUX flag set in cmake/platforms.cmake or APPLE).

Copilot uses AI. Check for mistakes.
Comment thread CMakeLists.txt Outdated
Comment on lines +56 to +63
if(NOT MSVC)
include(CheckIPOSupported)
check_ipo_supported(RESULT ov_tokenizers_ipo_supported OUTPUT ov_tokenizers_ipo_error LANGUAGES C CXX)
if(ov_tokenizers_ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
message(STATUS "IPO/LTO is enabled for Release builds")
else()
message(STATUS "IPO/LTO is not supported: ${ov_tokenizers_ipo_error}")
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON) is set as a normal variable, which will shadow any user-provided cache setting (e.g., -DCMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE=OFF) and makes LTO hard to opt out from. Consider respecting an existing cache value or adding a dedicated option (e.g., ENABLE_LTO) so packagers/consumers can disable it when needed.

Suggested change
if(NOT MSVC)
include(CheckIPOSupported)
check_ipo_supported(RESULT ov_tokenizers_ipo_supported OUTPUT ov_tokenizers_ipo_error LANGUAGES C CXX)
if(ov_tokenizers_ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
message(STATUS "IPO/LTO is enabled for Release builds")
else()
message(STATUS "IPO/LTO is not supported: ${ov_tokenizers_ipo_error}")
option(ENABLE_LTO "Enable IPO/LTO for Release builds when supported" ON)
if(NOT MSVC)
if(ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ov_tokenizers_ipo_supported OUTPUT ov_tokenizers_ipo_error LANGUAGES C CXX)
if(ov_tokenizers_ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
message(STATUS "IPO/LTO is enabled for Release builds")
else()
message(STATUS "IPO/LTO is not supported: ${ov_tokenizers_ipo_error}")
endif()
else()
message(STATUS "IPO/LTO is disabled by ENABLE_LTO=OFF")

Copilot uses AI. Check for mistakes.
@apaniukov apaniukov force-pushed the reduce-binary-size-linux-mac branch from 9134160 to 0fea02d Compare April 7, 2026 18:10
@github-actions github-actions Bot added the CI label Apr 8, 2026
Comment thread src/CMakeLists.txt
set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_OPTIONS "${extra_flags}")

# Enable LTO in Release build reduces the binary size by around 2 times
if(NOT MSVC AND CMAKE_BUILD_TYPE STREQUAL "Release")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would make it as in genai:
via INTERPROCEDURAL_OPTIMIZATION_RELEASE property and ENABLE_LTO cmake flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants