summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Heap
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-10-05 18:44:31 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-05 18:52:00 +0200
commit83bd6754776e8f3290c460feb28f261cffad6a9b (patch)
tree236fe3c0ee94d97c6c19cb1428c535edb3e5eb64 /Userland/Libraries/LibJS/Heap
parent19fc225b455957cf81d2038571a7f3713c01b555 (diff)
downloadserenity-83bd6754776e8f3290c460feb28f261cffad6a9b.zip
LibJS: Make WeakContainer pruning do less work
Instead of iterating *all* swept cells when pruning weak containers, only iterate the cells actually *in* the container. Also, instead of compiling a list of all swept cells, we can simply check the Cell::state() flag to know if something should be pruned.
Diffstat (limited to 'Userland/Libraries/LibJS/Heap')
-rw-r--r--Userland/Libraries/LibJS/Heap/Heap.cpp6
1 files changed, 1 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp
index 43a8d41b87..a3aef36e0e 100644
--- a/Userland/Libraries/LibJS/Heap/Heap.cpp
+++ b/Userland/Libraries/LibJS/Heap/Heap.cpp
@@ -216,22 +216,18 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure
dbgln_if(HEAP_DEBUG, "sweep_dead_cells:");
Vector<HeapBlock*, 32> empty_blocks;
Vector<HeapBlock*, 32> full_blocks_that_became_usable;
- Vector<Cell*> swept_cells;
size_t collected_cells = 0;
size_t live_cells = 0;
size_t collected_cell_bytes = 0;
size_t live_cell_bytes = 0;
- auto should_store_swept_cells = !m_weak_containers.is_empty();
for_each_block([&](auto& block) {
bool block_has_live_cells = false;
bool block_was_full = block.is_full();
block.template for_each_cell_in_state<Cell::State::Live>([&](Cell* cell) {
if (!cell->is_marked()) {
dbgln_if(HEAP_DEBUG, " ~ {}", cell);
- if (should_store_swept_cells)
- swept_cells.append(cell);
#ifdef JS_TRACK_ZOMBIE_CELLS
if (m_zombify_dead_cells) {
cell->set_state(Cell::State::Zombie);
@@ -269,7 +265,7 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure
}
for (auto& weak_container : m_weak_containers)
- weak_container.remove_swept_cells({}, swept_cells.span());
+ weak_container.remove_dead_cells({});
if constexpr (HEAP_DEBUG) {
for_each_block([&](auto& block) {