diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-22 19:54:52 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 23:03:36 +0200 |
commit | d92548c5b0203eb24885d1acb2d0555c05bfe702 (patch) | |
tree | bb29f0e01051cd2a13ce91fdef15747655470693 /AK | |
parent | 3ff0a3aa4b616fc448ffa7ed0b093879fe04d3ee (diff) | |
download | serenity-d92548c5b0203eb24885d1acb2d0555c05bfe702.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Queue.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/Queue.h b/AK/Queue.h index d52026f107..c87750a879 100644 --- a/AK/Queue.h +++ b/AK/Queue.h @@ -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; } |