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>
A recent change in that area triggered Clang-SA to rescan the code and
complain about this pre-existing bug: If receiver == nullptr, then the
`previous` member was never initialized.
Fix by null'ing it using NSDMI. This is a trivial type, the compiler
will be able to avoid the redundant write.
Amends ab92b9e40025dcf08c14232de762a268201a78b4(!).
Pick-to: 6.7 6.6 6.5 6.2 5.15
Change-Id: Ideed71f0f36d5f896fb6a4614f233757c1371ee3
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
The atomic pointer "connections" is always populated under
mutex in QObjectPrivate::ensureConnectionData() but isn't necessarily
read under mutex protection (e.g. in maybeSignalConnected()).
This caused a data race, fixed by using storeRelease and loadAcquired.
Task-number: QTBUG-100336
Pick-to: 6.7 6.6 6.5
Change-Id: Ifd605e65122248eb08f49e036fdda6e6564226bc
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Convert tagged pointer to an encapsulated tagged pointer type, and clean
up where it is used.
Change-Id: I9cf5b8d1dfa345eebaa185e44d762d5008769480
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Partially reverts 06c2478
Even though these structs are not meant to be used anywhere outside
QObject, some special applications like Gammaray need them to get
details about connections.
Pick-to: 6.4
Fixes: QTBUG-104734
Change-Id: Ied73021e317cc6aed6192c229d9450ae48b6774c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>