Skip to content

Commit 9aa9054

Browse files
committed
Reduce default allocator heap size. Add GC check to Array::with_size()
1 parent dcd2167 commit 9aa9054

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

src/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Alloc
1515
{
1616
pub fn new() -> Self
1717
{
18-
Self::with_size(64 * 1024 * 1024)
18+
Self::with_size(32 * 1024 * 1024)
1919
}
2020

2121
pub fn with_size(mem_size_bytes: usize) -> Self

src/array.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,15 @@ impl Array
145145
}
146146
}
147147

148-
pub fn array_with_size(actor: &mut Actor, _self: Value, num_elems: Value, fill_val: Value) -> Result<Value, String>
148+
pub fn array_with_size(actor: &mut Actor, _self: Value, num_elems: Value, mut fill_val: Value) -> Result<Value, String>
149149
{
150150
let num_elems = num_elems.unwrap_usize();
151+
152+
actor.gc_check(
153+
size_of::<Array>() + size_of::<Value>() * num_elems,
154+
&mut [&mut fill_val]
155+
);
156+
151157
let mut elems = actor.alloc.alloc_table(num_elems).unwrap();
152158
unsafe { (&mut *elems).fill(fill_val); }
153159
let arr = Array { elems, len: num_elems };

src/vm.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,11 @@ impl Actor
941941
// Try to copy all objects into the new allocator
942942
if try_copy(self, &mut dst_alloc, &mut dst_map, extra_roots).is_err() {
943943
// If the copying fails, increase the heap size and try again
944-
new_mem_size = (new_mem_size * 5) / 4;
945-
println!("Increasing heap size to {} bytes", new_mem_size);
944+
new_mem_size = (new_mem_size * 3) / 2;
945+
println!(
946+
"Increasing heap size to {} bytes",
947+
thousands_sep(new_mem_size),
948+
);
946949
continue;
947950
}
948951

@@ -951,7 +954,7 @@ impl Actor
951954
let bytes_free = dst_alloc.bytes_free();
952955
if bytes_free < min_free_bytes {
953956
// Increase the heap size and try again
954-
new_mem_size = (new_mem_size * 5) / 4;
957+
new_mem_size = (new_mem_size * 3) / 2;
955958
println!(
956959
"Increasing heap size to {} bytes",
957960
thousands_sep(new_mem_size),

tests/gc_alloc_arrays.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
for (let var i = 0; i < 2_000_000; ++i)
1+
for (let var i = 0; i < 1_000_000; ++i)
22
{
33
let a = [0, 1, 2, 3, 4];
44
assert(a.len == 5);

tests/gc_linked_list.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Node
99

1010
let var list = nil;
1111

12-
for (let var n = 0; n < 2_000; ++n)
12+
for (let var n = 0; n < 1_000; ++n)
1313
{
1414
list = nil;
1515

tests/gc_list_extend.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Node
88
}
99

1010
let var list = nil;
11-
let num_nodes = 2_500_000;
11+
let num_nodes = 1_000_000;
1212

1313
for (let var i = 0; i < num_nodes; ++i)
1414
{

tests/gc_str_concat.psh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let var str = nil;
22

3-
for (let var n = 0; n < 1000; ++n)
3+
for (let var n = 0; n < 500; ++n)
44
{
55
str = "";
66

0 commit comments

Comments
 (0)