Enable lld ICF for the Python bindings on Linux - #6535
Merged
Conversation
Folds byte-identical template instantiations: mrmeshpy.so -11% unpacked, -2.3 MB compressed per wheel; full distro test matrix passed on an ICF build.
adalisk-emikhaylov
approved these changes
Aug 6, 2026
Contributor
Author
|
Overlap with the table-driven bindings rework (mrbind#42 / #6544) re-measured on the stacked dry run https://github.com/MeshInspector/MeshLib/actions/runs/31156684018: on top of #42, ICF still folds x86_64 mrmeshpy.so 14.80 → 12.39 MB zip (−2.41 MB, −16.3%) — same absolute win as standalone. The two optimizations bite disjoint bytes (#42 removes near-duplicates ICF can't fold; ICF folds the byte-identical per-shape residue), so this PR's numbers stand regardless of merge order. Combined: 19.32 → 12.39 MB zip (−35.8%). |
Fedr
added a commit
that referenced
this pull request
Aug 7, 2026
Enable lld's Identical Code Folding in the conservative `safe` mode for non-Debug Linux builds of the MeshLib libraries, complementing `--icf=all` for the Python bindings (#6535). `safe` folds only address-insignificant functions, so function pointers stay comparable. Applied inside the existing lld block rather than behind a linker probe of its own: GNU ld has no ICF at all, and `safe` folding reads Clang's `.llvm_addrsig` address-significance table, which GCC does not emit -- so no non-lld row can use the option. macOS is excluded because Apple's linker already deduplicates by default, emscripten because folding there happens in Binaryen instead. Raw shared-library size drops 2.2% on x64 (-1.35 MB) and 2.4% on arm64 (-1.57 MB), with `libMRVoxels.so` down 4.6-5.3%. The xz-compressed package moves only -0.08%: what ICF removes is duplicated code, which the compressor was already encoding as back-references, so the gain is in installed footprint rather than download size.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable lld's identical code folding when linking the Python bindings on Linux. lld is already the bindings linker there, so this is one linker flag in
generate.mk's release preset. No-ffunction-sectionsis needed for the per-function granularity ICF requires: the bindings compile with-flto=thin, and lld's LTO code generation unconditionally emits a section per function (lld/ELF/LTO.cpp: "Always emit a section per function/datum with LTO"); the only non-LTO object in the link is the single-function libstdc++ fs-path stub.Motivation: a symbol-level breakdown of
mrmeshpy.so(from a one-off unstripped build) shows its 33 MB of code is ~193k tiny functions — mrbind registration/wrapper instantiations (~60%) and pybind11cpp_function/caster machinery (~31%) — averaging a few hundred bytes each, many byte-identical after-Oz. ICF folds those:mrmeshpy.so(manylinux x86_64)--icf=safe--icf=all(this PR)That is −2.3 MB compressed per Linux wheel and −7 MB installed, for free at link time.
Why
=allrather than=safe:--icf=allmay fold functions whose addresses are observably distinct, which strictly speaking breaks C++ function-pointer identity. Nothing in the bindings relies on wrapper-function pointer identity (pybind11 stores the pointers to call them, never compares them), and the full 7-distro × 2-arch wheel test matrix passed on an--icf=allbuild (run 31108103358, all 14manylinux-pip-testjobs green). If reviewers prefer the conservative variant,safeis a one-word change costing 0.6 MB compressed (measured).(The measurement runs also had explicit
-ffunction-sections -fdata-sectionscompile flags; per the above they are no-ops for the LTO objects, so they were dropped from the final diff.)Gated to Linux because that's where it's measured and where lld is already in use; Windows (
lld-link/OPT:ICFsemantics) and macOS (ld64.lld --icf) are possible follow-ups with their own measurements.