diff --git a/src/plan/tracing.rs b/src/plan/tracing.rs index 739caa657a..6876fe4a04 100644 --- a/src/plan/tracing.rs +++ b/src/plan/tracing.rs @@ -1,7 +1,7 @@ //! This module contains code useful for tracing, //! i.e. visiting the reachable objects by traversing all or part of an object graph. -use crate::scheduler::gc_work::{ProcessEdgesWork, SlotOf}; +use crate::scheduler::gc_work::{ProcessEdgesWork, SlotOf, EDGES_WORK_BUFFER_SIZE}; use crate::scheduler::{GCWorker, WorkBucketStage}; use crate::util::ObjectReference; use crate::vm::SlotVisitor; @@ -25,7 +25,7 @@ pub struct VectorQueue { impl VectorQueue { /// Reserve a capacity of this on first enqueue to avoid frequent resizing. - const CAPACITY: usize = 4096; + const CAPACITY: usize = EDGES_WORK_BUFFER_SIZE; /// Create an empty `VectorObjectQueue`. pub fn new() -> Self { diff --git a/src/scheduler/gc_work.rs b/src/scheduler/gc_work.rs index 28d04c6874..6ec06a608d 100644 --- a/src/scheduler/gc_work.rs +++ b/src/scheduler/gc_work.rs @@ -10,6 +10,14 @@ use crate::*; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +/// Buffer size for [`ProcessEdgesWork`] work packets. This constant is exposed to binding +/// developers so that they can use this value for places in their binding that interface with the +/// work packet system, specifically the transitive closure via `ProcessEdgesWork` work packets +/// such as roots gathering code or weak reference processing. In order to have better load +/// balancing, it is recommended that binding developers use this constant to split work up into +/// different work packets. +pub const EDGES_WORK_BUFFER_SIZE: usize = 4096; + pub struct ScheduleCollection; impl GCWork for ScheduleCollection { @@ -556,7 +564,7 @@ pub trait ProcessEdgesWork: /// Higher capacity means the packet will take longer to finish, and may lead to /// bad load balancing. On the other hand, lower capacity would lead to higher cost /// on scheduling many small work packets. It is important to find a proper capacity. - const CAPACITY: usize = 4096; + const CAPACITY: usize = EDGES_WORK_BUFFER_SIZE; /// Do we update object reference? This has to be true for a moving GC. const OVERWRITE_REFERENCE: bool = true; /// If true, we do object scanning in this work packet with the same worker without scheduling overhead.