-
-
Notifications
You must be signed in to change notification settings - Fork 616
Description
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
GcConfigstruct with fields for threshold and used-space percentage. - Implement public
gc_config()andset_gc_config()functions to get/set the current thread-local GC config. - Integrate with
ContextBuilderso 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
ContextBuildercorrectly 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.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels