Skip to content

Commit

Permalink
Add #[unsafe_ignore_trace] to memoization table
Browse files Browse the repository at this point in the history
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
  • Loading branch information
caioraposo committed Sep 23, 2022
1 parent 0e5c09d commit 624566c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/runtime/value/function.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::{
cell::RefCell,
cmp::Ordering,
collections::HashMap,
fmt::{self, Debug},
hash::{Hash, Hasher},
rc::Rc,
};

use gc::{Gc, GcCell, Finalize, Trace};
Expand Down Expand Up @@ -75,7 +77,8 @@ pub struct HushFun {
// If memoization is active.
pub is_memoized: bool,
// Memoization table.
pub memo_table: Gc<GcCell<HashMap<Vec<Value>, Value>>>,
#[unsafe_ignore_trace]
pub memo_table: Rc<RefCell<HashMap<Vec<Value>, Value>>>,
pub pos: SourcePos,
}

Expand All @@ -96,7 +99,7 @@ impl HushFun {
body,
context: Gc::new(context),
is_memoized,
memo_table: Gc::new(GcCell::new(memo_table)),
memo_table: Rc::new(RefCell::new(memo_table)),
pos,
}
}
Expand Down

0 comments on commit 624566c

Please sign in to comment.