Skip to content

Commit 624566c

Browse files
committed
Add #[unsafe_ignore_trace] to memoization table
Using Gc for memo_table was degrading the runtime execution of some algorithms due to the garbage collector tracing the memoization table. Replacing Gc with Rc to prevent a panic caused by the macro. see: Manishearth/rust-gc#52
1 parent 0e5c09d commit 624566c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/runtime/value/function.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::{
2+
cell::RefCell,
23
cmp::Ordering,
34
collections::HashMap,
45
fmt::{self, Debug},
56
hash::{Hash, Hasher},
7+
rc::Rc,
68
};
79

810
use gc::{Gc, GcCell, Finalize, Trace};
@@ -75,7 +77,8 @@ pub struct HushFun {
7577
// If memoization is active.
7678
pub is_memoized: bool,
7779
// Memoization table.
78-
pub memo_table: Gc<GcCell<HashMap<Vec<Value>, Value>>>,
80+
#[unsafe_ignore_trace]
81+
pub memo_table: Rc<RefCell<HashMap<Vec<Value>, Value>>>,
7982
pub pos: SourcePos,
8083
}
8184

@@ -96,7 +99,7 @@ impl HushFun {
9699
body,
97100
context: Gc::new(context),
98101
is_memoized,
99-
memo_table: Gc::new(GcCell::new(memo_table)),
102+
memo_table: Rc::new(RefCell::new(memo_table)),
100103
pos,
101104
}
102105
}

0 commit comments

Comments
 (0)