buffer update opt: Skip releaseFreeSlots when no frees are pending (#9437)

This commit is contained in:
Doris Wu
2025-11-15 10:23:27 +08:00
committed by GitHub
parent aa4f1910b8
commit aa4e2c56b5
2 changed files with 17 additions and 3 deletions

View File

@@ -142,7 +142,11 @@ void BufferAllocator::retire(AllocationId id) {
InternalSlotNode* targetNode = getNodeById(id);
assert_invariant(targetNode != nullptr);
targetNode->slot.isAllocated = false;
Slot& slot = targetNode->slot;
slot.isAllocated = false;
if (slot.gpuUseCount == 0) {
mHasPendingFrees = true;
}
}
void BufferAllocator::acquireGpu(AllocationId id) {
@@ -157,10 +161,18 @@ void BufferAllocator::releaseGpu(AllocationId id) {
assert_invariant(targetNode != nullptr);
assert_invariant(targetNode->slot.gpuUseCount > 0);
targetNode->slot.gpuUseCount--;
Slot& slot = targetNode->slot;
slot.gpuUseCount--;
if (slot.gpuUseCount == 0 && !slot.isAllocated) {
mHasPendingFrees = true;
}
}
void BufferAllocator::releaseFreeSlots() {
if (!mHasPendingFrees) {
return;
}
auto curr = mSlotPool.begin();
while (curr != mSlotPool.end()) {
if (!curr->slot.isFree()) {
@@ -199,6 +211,7 @@ void BufferAllocator::releaseFreeSlots() {
curr = next;
}
mHasPendingFrees = false;
}
BufferAllocator::allocation_size_t BufferAllocator::getTotalSize() const noexcept {

View File

@@ -113,8 +113,9 @@ private:
[[nodiscard]] InternalSlotNode* getNodeById(AllocationId id) const noexcept;
bool mHasPendingFrees = false;
allocation_size_t mTotalSize;
const allocation_size_t mSlotSize; // Size of a single slot in bytes.
const allocation_size_t mSlotSize; // Size of a single slot in bytes
std::list<InternalSlotNode> mSlotPool; // All slots, including both allocated and freed
std::multimap</*slot size*/allocation_size_t, InternalSlotNode*> mFreeList;
std::unordered_map</*slot offset*/allocation_size_t, InternalSlotNode*> mOffsetMap;