Bug 287447 - libllvm, libclang, and liblldb converted into shared libraries - performance degradation
Summary: libllvm, libclang, and liblldb converted into shared libraries - performance ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-STABLE
Hardware: Any Any
: --- Affects Many People
Assignee: Dimitry Andric
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2025-06-11 12:20 UTC by Ivan Rozhuk
Modified: 2026-03-27 14:17 UTC (History)
12 users (show)

See Also:


Attachments
patch (22.84 KB, patch)
2025-10-06 21:37 UTC, Ivan Rozhuk
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Rozhuk 2025-06-11 12:20:46 UTC
https://cgit.freebsd.org/src/commit/?id=2e47f35be5dc

It is dramatically increase configure time, and build time.


Before commit:

root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h make configure
...
-- Build files have been written to: /tmp/ports/usr/ports/net/ssdpd/work/.build
	3.03s real		1.80s user		1.28s sys


root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h cc -v
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
	0.01s real		0.00s user		0.01s sys
root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h cc -v
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
	0.01s real		0.00s user		0.00s sys
root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h cc -v
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
	0.01s real		0.00s user		0.01s sys

Build world+kernell: ~13m (with ccache)



After:
root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h make configure
...
-- Build files have been written to: /tmp/ports/usr/ports/net/ssdpd/work/.build
	12.79s real		11.99s user		0.85s sys

root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h cc -v
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
	0.16s real		0.15s user		0.00s sys
root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h cc -v
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
	0.16s real		0.15s user		0.01s sys
root@rimwksv:/usr/ports/net/ssdpd# /usr/bin/time -h cc -v
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
	0.16s real		0.14s user		0.02s sys

Build world+kernell: ~30m (with ccache)
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2025-06-11 16:06:10 UTC
I think this was more or less expected, since loading executables depending on (largish) dynamic libraries is almost always slower than linking all those libraries in statically. In addition, the executables are now PIE which will also cause some performance loss, but it will probably be negligible relative to the dynamic linking itself.

When I was working on this patch I was considering a WITH/WITHOUT option to enable or disable dynamic linking, but that made it quite a bit more complicated, and during the review it did not seem that necessary.

Maybe we can reconsider such an option?
Comment 2 Ivan Rozhuk 2025-06-11 16:52:14 UTC
Is there any profit with this option on?
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2025-06-11 17:04:52 UTC
(In reply to Ivan Rozhuk from comment #2)
The same as with all other dynamically linked programs: smaller sizes, more sharing of code and data between binaries, slightly increased security due to randomized load addresses, etc. Also the possibility of upgrading the shared libraries independently of the binaries, though that is not applicable in this case.
Comment 4 Ivan Rozhuk 2025-06-11 19:01:42 UTC
I can buy more memory in shop but I can not buy time.
I do not care security while run compiler/linker.
Only time and result meter.

I mean there is no usable profit from this change, only performance degradation.
Comment 5 Ivan Rozhuk 2025-10-06 21:37:31 UTC
Created attachment 264358 [details]
patch

I use this path with stable/14 to get back adequate build performance.
Comment 6 Ivan Rozhuk 2025-12-08 01:53:16 UTC
According to https://llvm.org/docs/CMake.html
"BUILD_SHARED_LIBS is only recommended for use by LLVM developers. If you want to build LLVM as a shared library, you should use the LLVM_BUILD_LLVM_DYLIB option."

This also affect all devel/llvm* ports.
Comment 7 Ivan Rozhuk 2025-12-08 12:05:06 UTC
A bit more benchmarks devel/llvm19 and /usr/ports/net/ssdpd

dyn -DLLVM_LINK_LLVM_DYLIB=ON
/usr/bin/time -h make
3.83s real		2.84s user		2.60s sys
3.82s real		2.90s user		2.60s sys
3.81s real		2.75s user		2.66s sys
/usr/bin/time -h make configure
3.53s real		1.76s user		1.81s sys
3.39s real		1.87s user		1.57s sys
3.49s real		1.96s user		1.57s sys

/usr/bin/time -h /usr/local/llvm19/bin/clang-19 -v
0.03s real		0.01s user		0.01s sys
0.03s real		0.01s user		0.02s sys
0.03s real		0.01s user		0.01s sys


static -DLLVM_LINK_LLVM_DYLIB=OFF
/usr/bin/time -h make
2.45s real		1.59s user		1.80s sys
2.42s real		1.64s user		1.73s sys
2.40s real		1.62s user		1.77s sys
/usr/bin/time -h make configure
2.14s real		1.02s user		1.17s sys
2.14s real		1.01s user		1.18s sys
2.18s real		1.01s user		1.22s sys

/usr/bin/time -h /usr/local/llvm19/bin/clang-19 -v
0.00s real		0.00s user		0.00s sys
0.00s real		0.00s user		0.00s sys
0.00s real		0.00s user		0.00s sys


System clang build as static
/usr/bin/time -h make
2.09s real		3.77s user		1.08s sys
1.92s real		1.56s user		0.94s sys
1.92s real		1.46s user		1.01s sys
/usr/bin/time -h make configure
1.71s real		1.08s user		0.63s sys
1.74s real		1.11s user		0.62s sys
1.65s real		0.99s user		0.67s sys

/usr/bin/time -h cc -v
0.00s real		0.00s user		0.00s sys
0.00s real		0.00s user		0.00s sys
0.00s real		0.00s user		0.00s sys
Comment 8 Ivan Rozhuk 2025-12-08 22:36:53 UTC
Patch for llvm from ports that add option dyn link on/off: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291500
Comment 9 commit-hook freebsd_committer freebsd_triage 2025-12-23 21:05:15 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8d5a11cd0137d3ad70f6b06e063ea91a776d510a

commit 8d5a11cd0137d3ad70f6b06e063ea91a776d510a
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-06-18 10:06:25 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-12-23 21:01:40 +0000

    src.conf: Add WITH_LLVM_LINK_STATIC_LIBRARIES build knob

    In commit 2e47f35be5dc libllvm, libclang and liblldb were converted into
    private shared libraries. This allowed clang, lld, lldb, and other llvm
    tools to be linked against these shared libraries, which makes them
    smaller and avoids duplication.

    However, this also comes at the cost of some performance, since the
    dynamic libraries are quite large, and contain lots of long symbols
    (mangled C++ identifiers).

    Add a WITH_LLVM_LINK_STATIC_LIBRARIES build knob that can be used to go
    back to the previous behavior: libllvm, libclang and liblldb are built
    as internal static libraries, i.e. only available during buildworld, and
    fully linked into the various executables such as clang, lld, etc.

    PR:             287447
    Reviewed by:    emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D50956

 lib/clang/libclang/Makefile                               |  8 ++++----
 lib/clang/liblldb/Makefile                                | 13 ++++++++++++-
 lib/clang/libllvm/Makefile                                |  9 ++++-----
 share/man/man5/src.conf.5                                 |  9 ++++++++-
 share/mk/src.opts.mk                                      |  1 +
 tools/build/mk/OptionalObsoleteFiles.inc                  | 11 ++++++++---
 tools/build/options/WITH_LLVM_LINK_STATIC_LIBRARIES (new) |  6 ++++++
 usr.bin/clang/Makefile.inc                                |  2 +-
 usr.bin/clang/clang.prog.mk                               |  2 +-
 usr.bin/clang/lld/Makefile                                |  2 +-
 usr.bin/clang/lldb-server/Makefile                        |  5 +++++
 usr.bin/clang/lldb/Makefile                               |  5 +++++
 usr.bin/clang/llvm.prog.mk                                |  5 +++++
 13 files changed, 61 insertions(+), 17 deletions(-)
Comment 10 commit-hook freebsd_committer freebsd_triage 2026-01-02 20:52:11 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ded12d66a3ebdac657c24746f9b13d5d332f3cbd

commit ded12d66a3ebdac657c24746f9b13d5d332f3cbd
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-06-18 10:06:25 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2026-01-02 20:40:18 +0000

    src.conf: Add WITH_LLVM_LINK_STATIC_LIBRARIES build knob

    In commit 2e47f35be5dc libllvm, libclang and liblldb were converted into
    private shared libraries. This allowed clang, lld, lldb, and other llvm
    tools to be linked against these shared libraries, which makes them
    smaller and avoids duplication.

    However, this also comes at the cost of some performance, since the
    dynamic libraries are quite large, and contain lots of long symbols
    (mangled C++ identifiers).

    Add a WITH_LLVM_LINK_STATIC_LIBRARIES build knob that can be used to go
    back to the previous behavior: libllvm, libclang and liblldb are built
    as internal static libraries, i.e. only available during buildworld, and
    fully linked into the various executables such as clang, lld, etc.

    PR:             287447
    Reviewed by:    emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D50956

    (cherry picked from commit 8d5a11cd0137d3ad70f6b06e063ea91a776d510a)

 lib/clang/libclang/Makefile                               |  8 ++++----
 lib/clang/liblldb/Makefile                                | 13 ++++++++++++-
 lib/clang/libllvm/Makefile                                |  9 ++++-----
 share/man/man5/src.conf.5                                 |  9 ++++++++-
 share/mk/src.opts.mk                                      |  1 +
 tools/build/mk/OptionalObsoleteFiles.inc                  | 11 ++++++++---
 tools/build/options/WITH_LLVM_LINK_STATIC_LIBRARIES (new) |  6 ++++++
 usr.bin/clang/Makefile.inc                                |  2 +-
 usr.bin/clang/clang.prog.mk                               |  2 +-
 usr.bin/clang/lld/Makefile                                |  2 +-
 usr.bin/clang/lldb-server/Makefile                        |  5 +++++
 usr.bin/clang/lldb/Makefile                               |  5 +++++
 usr.bin/clang/llvm.prog.mk                                |  5 +++++
 13 files changed, 61 insertions(+), 17 deletions(-)
Comment 11 commit-hook freebsd_committer freebsd_triage 2026-01-02 20:53:14 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=908ca4f6af8a95d6c6ae65caed4371f96afb6409

commit 908ca4f6af8a95d6c6ae65caed4371f96afb6409
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-06-18 10:06:25 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2026-01-02 20:44:10 +0000

    src.conf: Add WITH_LLVM_LINK_STATIC_LIBRARIES build knob

    In commit 2e47f35be5dc libllvm, libclang and liblldb were converted into
    private shared libraries. This allowed clang, lld, lldb, and other llvm
    tools to be linked against these shared libraries, which makes them
    smaller and avoids duplication.

    However, this also comes at the cost of some performance, since the
    dynamic libraries are quite large, and contain lots of long symbols
    (mangled C++ identifiers).

    Add a WITH_LLVM_LINK_STATIC_LIBRARIES build knob that can be used to go
    back to the previous behavior: libllvm, libclang and liblldb are built
    as internal static libraries, i.e. only available during buildworld, and
    fully linked into the various executables such as clang, lld, etc.

    PR:             287447
    Reviewed by:    emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D50956

    (cherry picked from commit 8d5a11cd0137d3ad70f6b06e063ea91a776d510a)

 lib/clang/libclang/Makefile                               |  9 ++++-----
 lib/clang/liblldb/Makefile                                | 14 ++++++++++++--
 lib/clang/libllvm/Makefile                                | 10 ++++------
 share/man/man5/src.conf.5                                 |  9 ++++++++-
 share/mk/src.opts.mk                                      |  1 +
 tools/build/mk/OptionalObsoleteFiles.inc                  | 11 ++++++++---
 tools/build/options/WITH_LLVM_LINK_STATIC_LIBRARIES (new) |  6 ++++++
 usr.bin/clang/Makefile.inc                                |  2 +-
 usr.bin/clang/clang.prog.mk                               |  2 +-
 usr.bin/clang/lld/Makefile                                |  2 +-
 usr.bin/clang/lldb-server/Makefile                        |  5 +++++
 usr.bin/clang/lldb/Makefile                               |  5 +++++
 usr.bin/clang/llvm.prog.mk                                |  5 +++++
 13 files changed, 61 insertions(+), 20 deletions(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-01-02 20:53:15 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6acae3bbe3377aa59fe44c8646dfb778c034ca78

commit 6acae3bbe3377aa59fe44c8646dfb778c034ca78
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-06-18 10:06:25 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2026-01-02 20:48:56 +0000

    src.conf: Add WITH_LLVM_LINK_STATIC_LIBRARIES build knob

    In commit 2e47f35be5dc libllvm, libclang and liblldb were converted into
    private shared libraries. This allowed clang, lld, lldb, and other llvm
    tools to be linked against these shared libraries, which makes them
    smaller and avoids duplication.

    However, this also comes at the cost of some performance, since the
    dynamic libraries are quite large, and contain lots of long symbols
    (mangled C++ identifiers).

    Add a WITH_LLVM_LINK_STATIC_LIBRARIES build knob that can be used to go
    back to the previous behavior: libllvm, libclang and liblldb are built
    as internal static libraries, i.e. only available during buildworld, and
    fully linked into the various executables such as clang, lld, etc.

    PR:             287447
    Reviewed by:    emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D50956

    (cherry picked from commit 8d5a11cd0137d3ad70f6b06e063ea91a776d510a)

 lib/clang/libclang/Makefile                               |  9 ++++-----
 lib/clang/liblldb/Makefile                                | 14 ++++++++++++--
 lib/clang/libllvm/Makefile                                | 10 ++++------
 share/man/man5/src.conf.5                                 | 10 ++++++++--
 share/mk/src.opts.mk                                      |  1 +
 tools/build/mk/OptionalObsoleteFiles.inc                  | 11 ++++++++---
 tools/build/options/WITH_LLVM_LINK_STATIC_LIBRARIES (new) |  6 ++++++
 usr.bin/clang/Makefile.inc                                |  2 +-
 usr.bin/clang/clang.prog.mk                               |  2 +-
 usr.bin/clang/lld/Makefile                                |  2 +-
 usr.bin/clang/lldb-server/Makefile                        |  5 +++++
 usr.bin/clang/lldb/Makefile                               |  5 +++++
 usr.bin/clang/llvm.prog.mk                                |  5 +++++
 13 files changed, 61 insertions(+), 21 deletions(-)
Comment 13 Mark Linimon freebsd_committer freebsd_triage 2026-01-03 02:12:08 UTC
^Triage: committed and MFCed.
Comment 14 Ivan Rozhuk 2026-01-03 13:17:25 UTC
build world + install world + build kernel + install kernel + some time to cp obj from tmpfs to ssd + make delete old*...
Done with ccache.


"Update" from attached patch to committed:
5m37.47s real		38m12.80s user		11m35.34s sys

Same with committed patch without changes src.conf (no WITH_LLVM_LINK_STATIC_LIBRARIES / WITHOUT_LLVM_LINK_STATIC_LIBRARIES):
10m43.51s real		1h43m3.36s user		18m24.94s sys
9m21.25s real		1h26m56.18s user	17m14.38s sys
9m28.40s real		1h27m40.65s user	17m48.88s sys


WITH_LLVM_LINK_STATIC_LIBRARIES=
31m13.32s real		6h50m6.71s user		25m58.81s sys
5m20.03s real		34m47.16s user		16m2.86s sys
5m18.58s real		34m36.83s user		15m46.20s sys

Committed changes work fine.

Why WITH_LLVM_LINK_STATIC_LIBRARIES= is not default!?
1gb disk space is cheaper than CPU time.