Reorder member variables to reduce memory usage.

Review Request #122487 - Created Feb. 8, 2015 and submitted

Information
Volker Krause
kcoreaddons
master
53ca571...
Reviewers
kdeframeworks

The KJobPrivate one saves 24 bytes per instance, the others 8 bytes (on a 64 bit system).

Struct "Entry (DW_TAG_class_type, offset 393887)" is sub-optimally packed: 74/88 bytes, 592/704 bits, optimal size is: 80 bytes
class KDirWatchPrivate::Entry // location: /k/kde5/src/kcoreaddons/src/lib/io/kdirwatch_p.h:83
{
    time_t m_ctime; // member offset: 0, size: 8, alignment: 8
    int m_nlink; // member offset: 8, size: 4, alignment: 4
    // 4 byte(s) padding
    ino_t m_ino; // member offset: 16, size: 8, alignment: 8
    entryStatus m_status; // member offset: 24, size: 4, alignment: 4
    entryMode m_mode; // member offset: 28, size: 4, alignment: 4
    bool isDir; // member offset: 32, size: 1, alignment: 1
    // 7 byte(s) padding
    QList<KDirWatchPrivate::Client*> m_clients; // member offset: 40, size: 8, alignment: 8
    QList<KDirWatchPrivate::Entry*> m_entries; // member offset: 48, size: 8, alignment: 8
    QString path; // member offset: 56, size: 8, alignment: 8
    int msecLeft; // member offset: 64, size: 4, alignment: 4
    int freq; // member offset: 68, size: 4, alignment: 4
    bool dirty; // member offset: 72, size: 1, alignment: 1
    // 3 byte(s) padding
    int wd; // member offset: 76, size: 4, alignment: 4
    QList<QString> m_pendingFileChanges; // member offset: 80, size: 8, alignment: 8
}; // size: 88, alignment: 8

Struct "KJobPrivate (DW_TAG_class_type, offset 1112242)" is sub-optimally packed: 95/120 bytes, 760/960 bits, optimal size is: 96 bytes
class KJobPrivate // location: /k/kde5/src/kcoreaddons/src/lib/jobs/kjob_p.h:36
{
    __vtbl_ptr_type* _vptr.KJobPrivate; // member offset: 0, size: 8, alignment: 8
    KJob* q_ptr; // member offset: 8, size: 8, alignment: 8
    KJobUiDelegate* uiDelegate; // member offset: 16, size: 8, alignment: 8
    int error; // member offset: 24, size: 4, alignment: 4
    // 4 byte(s) padding
    QString errorText; // member offset: 32, size: 8, alignment: 8
    Unit progressUnit; // member offset: 40, size: 4, alignment: 4
    // 4 byte(s) padding
    QMap<KJob::Unit, long long unsigned int> processedAmount; // member offset: 48, size: 8, alignment: 8
    QMap<KJob::Unit, long long unsigned int> totalAmount; // member offset: 56, size: 8, alignment: 8
    long unsigned int percentage; // member offset: 64, size: 8, alignment: 8
    bool suspended; // member offset: 72, size: 1, alignment: 1
    // 3 byte(s) padding
    Capabilities capabilities; // member offset: 76, size: 4, alignment: 4
    QTimer* speedTimer; // member offset: 80, size: 8, alignment: 8
    bool isAutoDelete; // member offset: 88, size: 1, alignment: 1
    // 7 byte(s) padding
    QEventLoop* eventLoop; // member offset: 96, size: 8, alignment: 8
    QEventLoopLocker eventLoopLocker; // member offset: 104, size: 8, alignment: 8
    bool isFinished; // member offset: 112, size: 1, alignment: 1
    // 7 byte(s) padding
}; // size: 120, alignment: 8

Struct "KPluginLoaderPrivate (DW_TAG_class_type, offset 1584914)" is sub-optimally packed: 37/48 bytes, 296/384 bits, optimal size is: 40 bytes
class KPluginLoaderPrivate // location: /k/kde5/src/kcoreaddons/src/lib/plugin/kpluginloader.cpp:37
{
    KPluginLoader* q_ptr; // member offset: 0, size: 8, alignment: 8
    QString const name; // member offset: 8, size: 8, alignment: 8
    quint32 pluginVersion; // member offset: 16, size: 4, alignment: 4
    // 4 byte(s) padding
    QString errorString; // member offset: 24, size: 8, alignment: 8
    bool pluginVersionResolved; // member offset: 32, size: 1, alignment: 1
    // 7 byte(s) padding
    QPluginLoader* loader; // member offset: 40, size: 8, alignment: 8
}; // size: 48, alignment: 8
David Faure
Volker Krause
Review request changed

Status: Closed (submitted)

Milian Wolff

nice :) how did you find it - do you have a tool for that now or was this still requiring manual interpretation?

  1. The tool is getting better and now also exists in a single-purpose command line version, in the above mentioned repo. Results seem to be mostly correct, unless you have incomplete DWARF data or hit some corner cases. There is still lots of work to be done on improving the optimizer to properly support bitfield packing. For just finding padding gaps it's getting somewhat usable I think.
Loading...