|
|
@ -53,7 +53,9 @@ thread_local!(static BOA_GC: RefCell<BoaGc> = RefCell::new( BoaGc { |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
|
struct GcConfig { |
|
|
|
struct GcConfig { |
|
|
|
|
|
|
|
/// The threshold at which the garbage collector will trigger a collection.
|
|
|
|
threshold: usize, |
|
|
|
threshold: usize, |
|
|
|
|
|
|
|
/// The percentage of used space at which the garbage collector will trigger a collection.
|
|
|
|
used_space_percentage: usize, |
|
|
|
used_space_percentage: usize, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -63,7 +65,8 @@ struct GcConfig { |
|
|
|
impl Default for GcConfig { |
|
|
|
impl Default for GcConfig { |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
threshold: 1024, |
|
|
|
// Start at 1MB, the nursary size for V8 is ~1-8MB and SM can be up to 16MB
|
|
|
|
|
|
|
|
threshold: 1_048_576, |
|
|
|
used_space_percentage: 70, |
|
|
|
used_space_percentage: 70, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -191,6 +194,8 @@ impl Allocator { |
|
|
|
if gc.runtime.bytes_allocated > gc.config.threshold { |
|
|
|
if gc.runtime.bytes_allocated > gc.config.threshold { |
|
|
|
Collector::collect(gc); |
|
|
|
Collector::collect(gc); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Post collection check
|
|
|
|
|
|
|
|
// If the allocated bytes are still above the threshold, increase the threshold.
|
|
|
|
if gc.runtime.bytes_allocated |
|
|
|
if gc.runtime.bytes_allocated |
|
|
|
> gc.config.threshold / 100 * gc.config.used_space_percentage |
|
|
|
> gc.config.threshold / 100 * gc.config.used_space_percentage |
|
|
|
{ |
|
|
|
{ |
|
|
|