From d34d035022f9c7b9957cfb2abe0ba90486416ae2 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 26 Jan 2023 14:16:35 +0100 Subject: [PATCH] MemoryManager: Retain the end of a chunk when allocating a new one When we allocate a new chunk of memory, there may still be a bit of memory left at the end of the previous one. Throwing that away is a waste. Change-Id: I2b70b581cb835161b0819c3e11c2354010c6ca1c Reviewed-by: Qt CI Bot Reviewed-by: Fabian Kosmale --- src/qml/memory/qv4mm.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index a7892e9729..5c3be27014 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -522,6 +522,14 @@ HeapItem *BlockAllocator::allocate(size_t size, bool forceAllocation) { if (!m) { if (!forceAllocation) return nullptr; + if (nFree) { + // Save any remaining slots of the current chunk + // for later, smaller allocations. + size_t bin = binForSlots(nFree); + nextFree->freeData.next = freeBins[bin]; + nextFree->freeData.availableSlots = nFree; + freeBins[bin] = nextFree; + } Chunk *newChunk = chunkAllocator->allocate(); Q_V4_PROFILE_ALLOC(engine, Chunk::DataSize, Profiling::HeapPage); chunks.push_back(newChunk);