From 008f2b85ca4b12c4e04e82f380a7ad7486a46efa Mon Sep 17 00:00:00 2001 From: luc-blaeser Date: Fri, 27 Jan 2023 11:35:52 +0100 Subject: [PATCH] Optimization --- rts/motoko-rts/src/gc/incremental/partitioned_heap.rs | 4 ++++ .../src/gc/incremental/phases/evacuation_increment.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rts/motoko-rts/src/gc/incremental/partitioned_heap.rs b/rts/motoko-rts/src/gc/incremental/partitioned_heap.rs index 5392e6ca675..c1fdf81e037 100644 --- a/rts/motoko-rts/src/gc/incremental/partitioned_heap.rs +++ b/rts/motoko-rts/src/gc/incremental/partitioned_heap.rs @@ -83,6 +83,10 @@ impl Partition { self.dynamic_size } + pub fn marked_size(&self) -> usize { + self.marked_size + } + pub fn free_size(&self) -> usize { self.end_address() - self.dynamic_space_end() } diff --git a/rts/motoko-rts/src/gc/incremental/phases/evacuation_increment.rs b/rts/motoko-rts/src/gc/incremental/phases/evacuation_increment.rs index 9c914ed888a..18c4eb71531 100644 --- a/rts/motoko-rts/src/gc/incremental/phases/evacuation_increment.rs +++ b/rts/motoko-rts/src/gc/incremental/phases/evacuation_increment.rs @@ -70,6 +70,9 @@ impl<'a, M: Memory + 'a> EvacuationIncrement<'a, M> { pub unsafe fn evacuate_partition(&mut self, partition: &Partition) { debug_assert!(!partition.is_free()); debug_assert!(!partition.has_large_content()); + if partition.marked_size() == 0 { + return; + } let mut iterator = PartitionIterator::load_from(partition, &self.state, &mut self.time); while iterator.current_object().is_some() && !self.time.is_over() { let object = iterator.current_object().unwrap(); @@ -92,7 +95,12 @@ impl<'a, M: Memory + 'a> EvacuationIncrement<'a, M> { (*original).forward = new_address; debug_assert!(!copy.is_forwarded()); debug_assert!(original.is_forwarded()); - debug_assert!(copy.is_marked()); // Necessary to ensure field updates in the copy. + // The mark bit is necessary to ensure field updates in the copy. + debug_assert!(copy.is_marked()); + // However, updating the marked size statistics of target partition + // can be skipped, since that partition will not be considered for + // evacuation during the current GC run. + self.time.advance(size.as_usize()); #[cfg(debug_assertions)]