🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #96

[Bug 299387] rtld: dlopen() of a module with a large C++ dependency tree takes ~11 s of CPU; same libraries preloaded first take...

#96
From: 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
Technical Details
Message-ID: <bug-299387-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 299387] rtld: dlopen() of a module with a large C++ dependency
 tree takes ~11 s of CPU; same libraries preloaded first take ~2 s
Date: Wed, 14 Oct 2026 15:36:03 +0000
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-bugs@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-299387-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="82"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1791992163;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=G5PJJJlP5T1uJ3jyYemiz8a27hqY504tro0GJCRCWfs=;
	b=iHFlWUfbSMe8AVAoN+jR4WlEKn4hsgjoxq0o+5nDD+oDZ9mZkMPMRM0OPju/naiadNo1ef
	yPZXObiN+h5tYWlUNxp3mS0BEUrzEpa2ylnieZdVzcjCHT5/TDAksDjIHq1HwaEhI6i8Ky
	07X/SgYIzOSBa93q/39ShkPBgUlN1Gg/CLWUKEApY+lyzo6np8e13tS158wm/6y+HNgM1q
	i/qffubchblD9uxe1i8bLdkM5JIhqTUOTsHoDfu8sEEfD1CZbwqszfK4cPJKeklQIJYcV1
	l5rLM3vWBltaxQuPD5S2TLIlkbV7VuBiiKMaa0DV0s5XCfcvIUrI2lqCxlvWEg==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes