Skip to content

Commit

Permalink
Switch to non-send Gc implementation to improve performance and simpl…
Browse files Browse the repository at this point in the history
…ify code (#46)

* Add benchmarks

* Switch to non-send rwlock for gc to simplify code

* Add bench

* deep clone fix

* Move cont clones back in line to improve clarity
  • Loading branch information
maplant authored Dec 21, 2024
1 parent 7e3068d commit dd88133
Show file tree
Hide file tree
Showing 22 changed files with 546 additions and 596 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ jobs:
run: cargo clippy --all-targets -- -Dclippy::all -D warnings
- name: Test
run: cargo test
- name: Bench
run: cargo bench
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ derivative = "2"

[profile.release]
lto = true

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports", "async_tokio"] }

[[bench]]
name = "fib"
harness = false
29 changes: 29 additions & 0 deletions benches/fib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use scheme_rs::{env::Env, lex::Token, syntax::ParsedSyntax};

use criterion::*;

async fn fib() {
let top = Env::top().await;

let r6rs_tok = Token::tokenize_file(include_str!("fib.scm"), "fib.scm").unwrap();
let r6rs_sexprs = ParsedSyntax::parse(&r6rs_tok).unwrap();
for sexpr in r6rs_sexprs {
sexpr
.compile(&top, &None)
.await
.unwrap()
.eval(&top, &None)
.await
.unwrap();
}
}

fn fib_benchmark(c: &mut Criterion) {
c.bench_function("fib 100", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(fib)
});
}

criterion_group!(benches, fib_benchmark);
criterion_main!(benches);
8 changes: 8 additions & 0 deletions benches/fib.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(define (fib n)
(define (iter a b count)
(if (<= count 0)
a
(iter b (+ a b) (- count 1))))
(iter 0 1 n))

(fib 100)
3 changes: 2 additions & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ pub struct DefineFunc {
pub body: Body,
}

#[derive(Clone, Trace)]
#[derive(Clone, Trace, derive_more::Debug)]
pub struct DefineVar {
pub name: Identifier,
#[debug(skip)]
pub val: Arc<dyn Eval>,
}

Expand Down
3 changes: 1 addition & 2 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,7 @@ impl Compile for ast::DefineSyntax {
.eval(env, cont)
.await?
.require_one()?,
)
.await;
);
Ok(ast::DefineSyntax)
}
_ => Err(CompileDefineSyntaxError::BadForm(span.clone())),
Expand Down
Loading

0 comments on commit dd88133

Please sign in to comment.