AK: Avoid pagefaults when repeatedly enqueing/dequeing items in a Queue

When repeatedly enqueing and dequeing a single item in a Queue we end
up faulting in all the pages for the underlying Vector. This is a
performance issue - especially where the element type is large.
This commit is contained in:
Gunnar Beutner 2021-05-22 19:54:52 +02:00 committed by Andreas Kling
parent 3ff0a3aa4b
commit d92548c5b0

View file

@ -46,6 +46,13 @@ public:
m_index_into_first = 0;
}
--m_size;
if (m_size == 0 && !m_segments.is_empty()) {
// This is not necessary for correctness but avoids faulting in
// all the pages for the underlying Vector in the case where
// the caller repeatedly enqueues and then dequeues a single item.
m_index_into_first = 0;
m_segments.last()->data.clear_with_capacity();
}
return value;
}