🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: muc.lists.freebsd.bugs
2 messages
2 total messages Started by bugzilla-noreply Wed, 14 Oct 2026 15:36
[Bug 299387] rtld: dlopen() of a module with a large C++ dependency tree takes ~11 s of CPU; same libraries preloaded first take...
#96
Author: bugzilla-noreply
Date: Wed, 14 Oct 2026 15:36
115 lines
6586 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=299387

            Bug ID: 299387
           Summary: rtld: dlopen() of a module with a large C++ dependency
                    tree takes ~11 s of CPU; same libraries preloaded
                    first take ~2 s
           Product: Base System
           Version: 15.1-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: ste@umrk.org

Summary
A single dlopen() of a shared module with a large dependency tree (KiCad's
_pcbnew.kiface, 352 libraries in ldd output) takes about 10.9 s of CPU on my
machine, all of it in ld-elf.so.1. If the same dependency libraries are
dlopen()ed first, one by one, the dependencies take about 2 s and the module
itself 0.14 s. I do not know whether this is expected behaviour, so I am
reporting the measurements.

Environment
- GhostBSD 26.1-R15.0p13, based on FreeBSD 15.0-RELEASE-p13
  uname -a: FreeBSD host-ghostbsd 15.0-RELEASE-p13 FreeBSD 15.0-RELEASE-p13
n230765-65e896a6c619 GENERIC amd64
  freebsd-version: 15.0-RELEASE-p13
- CPU: AMD Opteron 6234 (12 cores, slow per core), ASUS KGPE-D16
- Packages: kicad 10.0.6, wxWidgets 3.2, OpenCASCADE 8.0 (libTK*), from pkg
- I have not tried stock FreeBSD 15.0. [Update this line if you do.]

Reproducer (needs the kicad package; python3 only)

  time python3 -c "import ctypes; ctypes.CDLL('/usr/local/bin/_pcbnew.kiface')"
  -> 10.85 s user, 0.07 s system, 99% CPU (repeatable, caches warm)

  time python3 -c "import ctypes;
ctypes.CDLL('/usr/local/bin/_eeschema.kiface')"
  -> 3.3 s, 99% CPU (283 libraries)

Same libraries pre-loaded, then the module:

  python3 - << 'EOF'
  import ctypes, subprocess, time
  k = '/usr/local/bin/_pcbnew.kiface'
  t0 = time.time()
  for l in
subprocess.run(['ldd',k],capture_output=True,text=True).stdout.splitlines():
      if '=>' in l:
          try: ctypes.CDLL(l.split('=>')[1].split('(')[0].strip())
          except OSError: pass
  t1 = time.time()
  try: ctypes.CDLL(k)
  except OSError: pass
  print(f"deps: {t1-t0:.2f}s  kiface itself: {time.time()-t1:.2f}s")
  EOF
  -> deps: 2.01 s  kiface itself: 0.14 s

(The 2.01 s includes running ldd.)

What I observed in the full application
- Starting kicad (the project manager, which loads all its .kiface modules at
  startup) took 45 s to the first window (about 30 s on earlier runs).
- With LD_PRELOAD set to the libTK* (OpenCASCADE) libraries from
  ldd _pcbnew.kiface, startup took 11 s:
    time env LD_PRELOAD="$(ldd /usr/local/bin/_pcbnew.kiface | awk
'/libTK/{print $3}' | tr '\n' ' ')" kicad
- LD_BIND_NOW=1 made startup slower (45 s, against ~30 s without it).
- During the delay one thread runs at 100% CPU and makes almost no system
  calls (truss showed about 1-3 calls per second for roughly 25 s).
- lldb backtrace of the busy main thread: the innermost frames are all in
  /libexec/ld-elf.so.1, called from libwx_baseu-3.2.so (dlopen) and
  libkicommon.so.10.0.6.

Other measurements
- Timing each library from the pcbnew tree individually showed no dominant
  one; only libkigal (0.55 s), libwx_gtk3u_gl (0.34 s) and
  libwx_gtk3u_webview (0.30 s) exceeded 0.2 s.
- The libraries have GNU_HASH tables (checked libTKernel).
- _pcbnew.kiface has about 189,000 relocation entries (readelf -r lines);
  _eeschema.kiface about 118,000. Eeschema has 62% of pcbnew's relocation
  entries but takes 30% of the load time, so relocation count alone does not
  explain it.
- No LD_* variables were set in my environment.

Expected behaviour
Loading the module in one dlopen() would cost about the same as loading its
dependencies first, as in the pre-load test above.

Not tested
- Stock FreeBSD 15.0 (as opposed to GhostBSD)
- A faster CPU, so I cannot say how much of this is specific to slow cores
- Which libraries or which load order matters; I preloaded only libTK*
- ctypes opens with RTLD_NOW, I believe, while KiCad's own loader may use
  lazy binding, so the Python reproducer is not identical to KiCad's path.
  The full-application numbers above are the real-world effect.

Impact
KiCad takes 30-45 s to start on this machine; 11 s with the LD_PRELOAD
workaround.

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 299387] rtld: dlopen() of a module with a large C++ dependency tree takes ~11 s of CPU; same libraries preloaded first take...
#124
Author: bugzilla-noreply
Date: Fri, 16 Oct 2026 16:07
17 lines
2742 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=299387

Dag-Erling Smørgrav <des@FreeBSD.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |des@FreeBSD.org
           Assignee|bugs@FreeBSD.org            |kib@FreeBSD.org

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads