Skip to content

Fold identical functions in the bindings on every platform, not just Linux - #6734

Open
Fedr wants to merge 4 commits into
masterfrom
icf-everywhere
Open

Fold identical functions in the bindings on every platform, not just Linux#6734
Fedr wants to merge 4 commits into
masterfrom
icf-everywhere

Conversation

@Fedr

@Fedr Fedr commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

--icf=all has been Linux-only since it was added, with the note "until lld-link (Windows) and ld64.lld (macOS) get their own measurements". Those measurements are now in, from #6731: every macOS leg linked the module with ICF and ran the full Python sanity suite on the result.

leg baseline with --icf=all sanity
macOS x64 Release 45,815,344 39,606,312 (-13.6%) pass
macOS arm64 Release 30,881,104 24,925,216 (-19.3%) pass
macOS arm64 Debug 32,046,672 25,803,472 (-19.5%) pass

__text alone drops 12.8% on x64 and 20.1% on arm64. arm64 folds more, as expected: fixed-width instructions make more of the ~190k near-duplicate template instantiations byte-identical.

What changed

Only the IS_LINUX guard around the flag, replaced by one that excludes the two platforms that cannot use it. It stays inside the MODE=release preset, because that is where -flto=thin comes from and lld's LTO codegen is what emits the per-function sections ICF folds; a MODE=none build has nothing to fold on any platform.

  • Emscriptenwasm-ld has no ICF. This was covered implicitly before (IS_LINUX is cleared when targeting Emscripten); now it is explicit.

  • Windows — nothing to add: lld-link already folds by default. Measured on the wheel build, which unlike build-test-windows.yml uses this preset:

    wheel module baseline /opt:icf /opt:noicf
    mrmeshpy.pyd 56,210,432 56,210,432 63,037,440 (+12.1%)
    mrcudapy.pyd 816,640 816,640 876,032 (+7.3%)

    /opt:icf is a no-op because ICF comes with /opt:ref in non-debug links, and disabling it costs 6.8 MB. The GNU spelling never reached the linker's logic there either — lld-link: warning: ignoring unknown argument '--icf=all', byte-identical output — so passing it on Windows would only add a warning.

Not included

-fomit-frame-pointer was measured in the same run and is not usable on macOS: it grows the module by 12-15% (Apple's ABI expects a frame pointer, so dropping it pushes functions out of the compact-unwind encodings into much bulkier DWARF entries) and it breaks the sanity suite outright — libc++abi: terminating due to uncaught exception of type pybind11::stop_iteration, i.e. unwinding stops finding handlers. Alignment padding is already nil under -Oz (477 bytes in a 34.7 MB __text), so there is nothing there either.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants