ladybird/Libraries/LibGC
Andreas Kling 2a67d3702a LibGC: Proactively collect garbage when the mutator goes idle
Collection was purely allocation-driven: a GC only ran once
allocation since the last collection passed a threshold of 7/4 of
the live set (floored at 8 MiB). A page that allocated garbage but
never reached that threshold held onto it indefinitely once it went
idle, so we never handed memory back to the system promptly.

Run a 4-second repeating timer while the mutator is allocating; on
each tick IdleCollectionPolicy picks one of three actions:

- Park the timer when nothing has been allocated since the last
  collection. The next allocation re-arms it, so a fully idle heap
  costs nothing.

- Collect when this tick's allocation rate fell below 1/4 of the
  peak rate seen this episode (the mutator left an active phase),
  provided at least threshold/16 of garbage has piled up, so we
  don't mark the whole live heap to reclaim a trivial amount.

- Otherwise let a watchdog collect after 15 ticks (60 seconds), so
  garbage cannot sit indefinitely on a heap that allocates too
  steadily to show a rate drop, or too slowly to clear the gate.

The GC heap is never completely silent in practice, since event-loop
housekeeping keeps queuing small objects like HTML tasks; that is
why the trigger watches for a relative rate drop rather than for
zero allocation.

The per-tick decision lives in IdleCollectionPolicy, separate from
the timer plumbing, with a unit test covering the rate-drop trigger,
the minimum-garbage gate, the watchdog, and parking when idle.
2026-05-15 15:55:12 +02:00
..
BlockAllocator.cpp LibGC: Avoid decommit worker during full sweep teardown 2026-05-15 15:54:28 +02:00
BlockAllocator.h LibGC: Avoid decommit worker during full sweep teardown 2026-05-15 15:54:28 +02:00
Cell.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
Cell.h LibGC: Add a Variant overload to Cell::Visitor 2026-05-15 08:51:17 +02:00
CellAllocator.cpp LibGC: Avoid decommit worker during full sweep teardown 2026-05-15 15:54:28 +02:00
CellAllocator.h LibGC: Avoid decommit worker during full sweep teardown 2026-05-15 15:54:28 +02:00
CMakeLists.txt LibGC: Move Web::WebDriver::HeapTimer to GC::Timer 2026-05-10 10:58:11 +02:00
ConservativeVector.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
ConservativeVector.h LibGC: Remove unused header in ConservativeVector 2026-02-23 12:15:23 +01:00
DeferGC.h Everywhere: Abandon Swift adoption 2026-02-17 10:48:09 -05:00
Forward.h LibGC: Move Web::WebDriver::HeapTimer to GC::Timer 2026-05-10 10:58:11 +02:00
Function.h LibGC: Clear functions during finalization 2026-05-10 10:58:11 +02:00
Heap.cpp LibGC: Proactively collect garbage when the mutator goes idle 2026-05-15 15:55:12 +02:00
Heap.h LibGC: Proactively collect garbage when the mutator goes idle 2026-05-15 15:55:12 +02:00
HeapBlock.cpp LibGC: Add live HeapBlock registry to fix weak container UAF 2026-05-10 10:58:11 +02:00
HeapBlock.h LibGC: Implement incremental sweeping for reduced GC pause times 2026-05-10 10:58:11 +02:00
HeapHashTable.h Libraries: Move #pragma once above include headers 2026-03-22 14:05:44 +01:00
HeapRoot.h LibGC+Meta: Look up and display stack frames for StackPointer roots 2026-03-01 21:50:51 +01:00
HeapVector.h LibGC: Include CellAllocator.h in HeapVector.h 2026-02-17 07:40:03 -05:00
IdleCollectionPolicy.h LibGC: Proactively collect garbage when the mutator goes idle 2026-05-15 15:55:12 +02:00
Internals.h LibGC: Always use 16 KiB as HeapBlock size 2025-12-19 20:21:07 -06:00
NanBoxedValue.h LibGC: Enable EXPLICIT_SYMBOL_EXPORT 2025-06-30 10:50:36 -06:00
Ptr.h LibGC: Delete operators ! and bool from GC::Ref 2025-10-29 21:20:10 +01:00
Root.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
Root.h LibGC: Remove unused header in Root 2026-02-23 12:15:23 +01:00
RootHashMap.cpp LibGC: Add GC::RootHashMap<...> template container 2025-05-03 17:33:54 +02:00
RootHashMap.h LibGC: Add static_assert for non-GC types in root containers 2026-05-07 13:00:52 +02:00
RootVector.cpp LibGC: Allow move-assigning RootVector instances 2025-04-19 02:03:43 +02:00
RootVector.h LibGC: Add static_assert for non-GC types in root containers 2026-05-07 13:00:52 +02:00
Timer.cpp LibWeb: Convert Document's cursor blink timer to GC::Timer 2026-05-10 10:58:11 +02:00
Timer.h LibWeb: Convert Document's cursor blink timer to GC::Timer 2026-05-10 10:58:11 +02:00
Weak.h LibGC+LibWeb: Add and use GC::weak_callback() 2026-02-26 08:03:50 -05:00
WeakBlock.cpp LibGC: Add GC::Weak<T> as an alternative to AK::WeakPtr<T> 2025-10-17 17:22:16 +02:00
WeakBlock.h LibGC: Add GC::Weak<T> as an alternative to AK::WeakPtr<T> 2025-10-17 17:22:16 +02:00
WeakContainer.cpp LibGC+Everywhere: Factor out a LibGC from LibJS 2024-11-15 14:49:20 +01:00
WeakContainer.h LibGC: Prune weak containers in stop-the-world phase of GC 2026-05-10 10:58:11 +02:00
WeakHashSet.h LibGC: Amortize pruning of dead entries in WeakHashSet 2026-03-08 20:49:28 +01:00
WeakInlines.h LibGC: Add missing & in Weak assignment 2026-03-14 21:35:06 -05:00