Skip to content

Commit 7c15171

Browse files
committed
Create a benchmark to profile GC performance issue
1 parent 03e109f commit 7c15171

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

benchmarks/gc_many_objs.psh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Node
2+
{
3+
init(self, val, next)
4+
{
5+
self.val = val;
6+
self.next = next;
7+
}
8+
}
9+
10+
let var list = nil;
11+
let num_nodes = 1_000_000;
12+
13+
// Grow the list, which will cause multiple GC cycles
14+
for (let var i = 0; i < num_nodes; ++i)
15+
{
16+
list = Node(1, list);
17+
}
18+
19+
// Trigger multiple GC cycles in a loop
20+
for (let var i = 0; i < 10_000; ++i)
21+
{
22+
ByteArray.with_size(100_000);
23+
}

src/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl Alloc
5555
/// This is primarily used to test the GC
5656
pub fn shrink_to(&mut self, new_size: usize)
5757
{
58+
assert!(new_size <= self.mem_size);
5859
assert!(self.next_idx <= new_size);
5960
self.mem_size = new_size;
6061

src/host.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ fn vm_shrink_heap(actor: &mut Actor, new_size: Value) -> Result<Value, String>
426426
{
427427
let new_size = unwrap_usize!(new_size);
428428

429+
if new_size > actor.alloc.mem_size() {
430+
return Err("requested heap size is larger than the current heap size".into());
431+
}
432+
429433
if actor.alloc.bytes_used() > new_size {
430434
return Err("requested heap size is smaller than bytes currently allocated".into());
431435
}

0 commit comments

Comments
 (0)