mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
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:
parent
3ff0a3aa4b
commit
d92548c5b0
Notes:
sideshowbarker
2024-07-18 09:01:58 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/d92548c5b02 Pull-request: https://github.com/SerenityOS/serenity/pull/8687 Reviewed-by: https://github.com/alimpfard
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user