Qt Base (Core, Gui, Widgets, Network, ...)
Go to file
Aurélien Brooke 03d5daf943 Add jemalloc support
Large graphical Qt applications heavily rely on heap allocations.
Jemalloc is a general-purpose malloc(3) implementation designed to
reduce heap fragmentation and improve scalability. It also provides
extensive tuning options.

Add a -jemalloc configure option, disabled by default. When enabled, Qt
and user code link to jemalloc, overriding the system's default
malloc().

Add cooperation with jemalloc for some Qt key classes: QArrayData (used
by QByteArray, QString and QList<T>), QBindingStoragePrivate,
QDataBuffer (used by the Qt Quick renderer), QDistanceFieldData,
QImageData, QObjectPrivate::TaggedSignalVector, QVarLengthArray.

This cooperation relies on two jemalloc-specific optimizations:
1. Efficient allocation via fittedMalloc():
   Determine the actual allocation size using nallocx(), then adjust the
   container’s capacity to match. This minimizes future reallocations.
   Note: we round allocSize to a multiple of sizeof(T) to ensure that
   we can later recompute the exact allocation size during deallocation.
2. Optimized deallocation via sizedFree():
   Use sdallocx(), which is faster than free when the allocation size
   is known, as it avoids internal size lookups.

Adapt the QVarLengthArray auto tests on capacity.

Non-standard functions docs are at https://jemalloc.net/jemalloc.3.html

[ChangeLog][QtCore] Added optional support for the jemalloc allocator,
and optimized memory allocations and deallocations in core Qt classes to
cooperate with it.

Change-Id: I6166e64e66876dee22662d3f3ea3e42a6647cfeb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2025-04-09 13:49:11 +02:00
.github/workflows
LICENSES Add REUSE.toml files 2024-11-05 14:36:16 +01:00
bin CMake: Don't hard-code "libexec" in qt-configure-module 2024-08-16 12:36:35 +02:00
cmake Add jemalloc support 2025-04-09 13:49:11 +02:00
coin Add QNX8.0 CI enablers 2025-03-24 19:01:57 +02:00
config.tests CMake: Remove superfluous precompile_header feature and config test 2025-03-07 12:02:47 +01:00
dist Add REUSE.toml files 2024-11-05 14:36:16 +01:00
doc Implement \tabs for DocBook 2025-04-03 21:39:13 +00:00
examples Doc: Add Alt-text to the Qt SQL examples 2025-04-09 07:15:08 +02:00
lib
libexec Android: fix warnings in runner script 2024-12-03 20:18:21 +00:00
mkspecs wasm: set jspi and wasm-exceptions flags for qmake 2025-03-13 12:57:00 +01:00
qmake QMake: Add ability to link against xcframeworks with Xcode 2025-03-13 18:25:37 +00:00
src Add jemalloc support 2025-04-09 13:49:11 +02:00
tests Add jemalloc support 2025-04-09 13:49:11 +02:00
util wasm: Fix Brotli compression in qtwasmserver.py 2025-03-26 19:35:48 +01:00
.cmake.conf Bump version to 6.10.0 2024-12-13 14:54:23 +00:00
.gitattributes
.gitignore Git ignore Visual Studio CMake build directories 2023-11-24 23:42:05 +01:00
.gitreview Add .gitreview file 2025-03-24 23:19:04 +01:00
.tag
CMakeLists.txt cmake: add _extra_files IDE target from heuristics 2024-04-12 08:36:01 +08:00
REUSE.toml Update licensing of files with infrastructure type 2025-03-12 16:04:26 +01:00
config_help.txt Add jemalloc support 2025-04-09 13:49:11 +02:00
configure Do not assume FHS in scripts 2024-06-25 11:44:00 +02:00
configure.bat configure.bat: Use call when calling the helper cmake scripts 2025-01-30 22:18:36 +01:00
configure.cmake CMake: Mention "Force assertions" in config.summary 2025-03-25 00:29:48 +01:00
dependencies.yaml
licenseRule.json Update licensing of files with infrastructure type 2025-03-12 16:04:26 +01:00
qt_cmdline.cmake CMake: Remove superfluous precompile_header feature and config test 2025-03-07 12:02:47 +01:00