allocate StateData and QList<StackSize> in the same memory segment to reduce memory footprint
Previously StateData was dynamically allocated and always contained a list with at least 1 element. Memory looked like:
StateData{
QAtomicInt ref;
defId;
QList<Stack>{ D* d; ptr; size; };
\-> D{ // variable sized class
QAtomicInt ref;
flags;
capacity;
Stack[capacity]; // variable sized
};
}
Several comments:
- The 2
QAtomicInthave the same value sinceStateDatais detached only when the stack changes. -
capacityis useful information only during the StateData construction (inAbstractHighlighter::highlightLine). After that, the list doesn't change. -
flagsis useless. -
ptrcan be deduced.
By making StateData a variable sized class, the new memory layout looks like this:
StateData{
QAtomicInt ref;
stackLen;
defId;
Stack[capacity]; // variable sized
};
capacity a temporary information used in the class that manipulates StateData.
With the test.c file repeated 6561 times (636K lines), Kate's memory consumption drops from 361M to 333M (-7.5%).
highlighter_benchmark is slightly faster (1%)