Skip to content

Commit 0b3ec9b

Browse files
authored
Make work packet buffer size configurable from one location (#1285)
Closes #1281
1 parent 129362d commit 0b3ec9b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/plan/tracing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module contains code useful for tracing,
22
//! i.e. visiting the reachable objects by traversing all or part of an object graph.
33
4-
use crate::scheduler::gc_work::{ProcessEdgesWork, SlotOf};
4+
use crate::scheduler::gc_work::{ProcessEdgesWork, SlotOf, EDGES_WORK_BUFFER_SIZE};
55
use crate::scheduler::{GCWorker, WorkBucketStage};
66
use crate::util::ObjectReference;
77
use crate::vm::SlotVisitor;
@@ -25,7 +25,7 @@ pub struct VectorQueue<T> {
2525

2626
impl<T> VectorQueue<T> {
2727
/// Reserve a capacity of this on first enqueue to avoid frequent resizing.
28-
const CAPACITY: usize = 4096;
28+
const CAPACITY: usize = EDGES_WORK_BUFFER_SIZE;
2929

3030
/// Create an empty `VectorObjectQueue`.
3131
pub fn new() -> Self {

src/scheduler/gc_work.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ use crate::*;
1010
use std::marker::PhantomData;
1111
use std::ops::{Deref, DerefMut};
1212

13+
/// Buffer size for [`ProcessEdgesWork`] work packets. This constant is exposed to binding
14+
/// developers so that they can use this value for places in their binding that interface with the
15+
/// work packet system, specifically the transitive closure via `ProcessEdgesWork` work packets
16+
/// such as roots gathering code or weak reference processing. In order to have better load
17+
/// balancing, it is recommended that binding developers use this constant to split work up into
18+
/// different work packets.
19+
pub const EDGES_WORK_BUFFER_SIZE: usize = 4096;
20+
1321
pub struct ScheduleCollection;
1422

1523
impl<VM: VMBinding> GCWork<VM> for ScheduleCollection {
@@ -556,7 +564,7 @@ pub trait ProcessEdgesWork:
556564
/// Higher capacity means the packet will take longer to finish, and may lead to
557565
/// bad load balancing. On the other hand, lower capacity would lead to higher cost
558566
/// on scheduling many small work packets. It is important to find a proper capacity.
559-
const CAPACITY: usize = 4096;
567+
const CAPACITY: usize = EDGES_WORK_BUFFER_SIZE;
560568
/// Do we update object reference? This has to be true for a moving GC.
561569
const OVERWRITE_REFERENCE: bool = true;
562570
/// If true, we do object scanning in this work packet with the same worker without scheduling overhead.

0 commit comments

Comments
 (0)