Skip to content

Feature: Expose Public GC Configuration API #5250

@workonlly

Description

@workonlly

Feature Description

Summary

Expose a public API to configure Boa’s garbage collector (GC) at runtime. This allows embedders and advanced users to tune memory management by setting allocation thresholds and used-space triggers.

Note: This aims to resolve the GC configuration TODO currently located in the engine initialization path (e.g., lib.rs:63).

Motivation

  • Enables embedders to control GC behavior for different workloads.
  • Provides the required groundwork for future GC redesigns and benchmarking.
  • Aligns with best practices in other major JavaScript engines (e.g., V8, SpiderMonkey).

Requirements

  • Create a public GcConfig struct with fields for threshold and used-space percentage.
  • Implement public gc_config() and set_gc_config() functions to get/set the current thread-local GC config.
  • Integrate with ContextBuilder so embedders can set the GC configuration at context creation.
  • Add unit tests for config normalization and roundtrip validation.
  • Add rustdoc documentation for the new API.

Acceptance Criteria

  • Users can successfully set and get the GC config at runtime.
  • Setting the config via ContextBuilder correctly applies to the newly created context.
  • All tests pass and documentation is successfully generated.

Example code
This Rust code should work and allow the embedder to successfully configure the GC upon context creation:

use boa_engine::ContextBuilder;
use boa_engine::gc::GcConfig;

let custom_gc_config = GcConfig::new(10_000_000, 80);
// or you can: GcConfig::default().with_threshold(10_000_000).with_used_space_percentage(80);

let mut context = ContextBuilder::new()
    .gc_config(custom_gc_config)
    .build()
    .expect("Failed to build context");

// Also a point to remmember The engine should now respect the custom thresholds during execution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions