1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:48:11 +00:00

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.
This commit is contained in:
Andreas Kling 2021-10-05 18:44:31 +02:00
parent 19fc225b45
commit 83bd675477
10 changed files with 39 additions and 35 deletions

View file

@ -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) {