Skip to content

Commit

Permalink
Merge branch 'new-benchmarks' into faster-ground-terms
Browse files Browse the repository at this point in the history
  • Loading branch information
mwillsey committed Nov 19, 2021
2 parents 7e8676d + b6f625d commit 43efab4
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 120 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ default.nix
TODO.md
flamegraph.svg
perf.data*
*.bench
.vscode/settings.json
10 changes: 0 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,10 @@ vectorize = { version = "0.2", optional = true }
# for the reports feature
serde_json = { version = "1", optional = true }

[[bench]]
name = "bench_tests"
harness = false

[dev-dependencies]
env_logger = {version = "0.7", default-features = false}
ordered-float = "1"

[dev-dependencies.iai]
# version = "*"
git = "https://github.com/mwillsey/iai"
rev = "c0b7cb47181e9577a6847caae53a2f0f881f45b2"
features = ["threadpool"]

[features]
wasm-bindgen = [ "instant/wasm-bindgen" ]
serde-1 = [ "serde", "indexmap/serde-1", "hashbrown/serde", "vectorize" ]
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# <img src="doc/egg.svg" alt="egg logo" height="40" align="left"> egg: egraphs good

[![Build Status](https://github.com/egraphs-good/egg/workflows/Build%20and%20Test/badge.svg?branch=main)](https://github.com/egraphs-good/egg/actions)
[![Crates.io](https://img.shields.io/crates/v/egg.svg)](https://crates.io/crates/egg)
[![Released Docs.rs](https://docs.rs/egg/badge.svg)](https://docs.rs/egg/)
[![Released Docs.rs](https://img.shields.io/crates/v/egg?color=blue&label=docs)](https://docs.rs/egg/)
[![Main branch docs](https://img.shields.io/badge/docs-main-blue)](https://egraphs-good.github.io/egg/egg/)

Are you using egg?
Expand Down
38 changes: 0 additions & 38 deletions benches/bench_tests.rs

This file was deleted.

34 changes: 0 additions & 34 deletions scripts/filter-iai-output.py

This file was deleted.

1 change: 1 addition & 0 deletions src/egraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
)
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn union_with_justification(
&mut self,
id1: Id,
Expand Down
2 changes: 1 addition & 1 deletion src/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ impl<L: Language> Explain<L> {
}
existance = next;
if seen_existance.contains(&existance) {
assert!(false, "Cycle in existance!");
panic!("Cycle in existance!");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ impl<L: Language> IndexMut<Id> for RecExpr<L> {
impl<L: Language + Display> Display for RecExpr<L> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.nodes.is_empty() {
write!(f, "()")
Display::fmt("()", f)
} else {
let s = self.to_sexp(self.nodes.len() - 1).to_string();
write!(f, "{}", s)
Display::fmt(&s, f)
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ pub struct Pattern<L> {
/// [`Pattern`].
pub type PatternAst<L> = RecExpr<ENodeOrVar<L>>;

impl<L: Language> PatternAst<L> {
/// Returns a new `PatternAst` with the variables renames canonically
pub fn alpha_rename(&self) -> Self {
let mut vars = HashMap::<Var, Var>::default();
let mut new = PatternAst::default();

fn mkvar(i: usize) -> Var {
let vs = &["?x", "?y", "?z", "?w"];
match vs.get(i) {
Some(v) => v.parse().unwrap(),
None => format!("?v{}", i - vs.len()).parse().unwrap(),
}
}

for n in self.as_ref() {
new.add(match n {
ENodeOrVar::ENode(_) => n.clone(),
ENodeOrVar::Var(v) => {
let i = vars.len();
ENodeOrVar::Var(*vars.entry(*v).or_insert_with(|| mkvar(i)))
}
});
}

new
}
}

impl<L: Language> Pattern<L> {
/// Creates a new pattern from the given pattern ast.
pub fn new(ast: PatternAst<L>) -> Self {
Expand Down
83 changes: 61 additions & 22 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,46 @@ pub enum StopReason {
Other(String),
}

/// A report containing data about an entire [`Runner`] run.
///
/// This is basically a summary of the [`Iteration`] data,
/// but summed across iterations.
/// See [`Iteration`] docs for details about fields.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde-1", derive(serde::Serialize))]
#[non_exhaustive]
#[allow(missing_docs)]
pub struct Report {
/// The number of iterations this runner performed.
pub iterations: usize,
pub stop_reason: StopReason,
pub egraph_nodes: usize,
pub egraph_classes: usize,
pub memo_size: usize,
pub rebuilds: usize,
pub total_time: f64,
pub search_time: f64,
pub apply_time: f64,
pub rebuild_time: f64,
}

impl std::fmt::Display for Report {
#[rustfmt::skip]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
writeln!(f, "Runner report")?;
writeln!(f, "=============")?;
writeln!(f, " Stop reason: {:?}", self.stop_reason)?;
writeln!(f, " Iterations: {}", self.iterations)?;
writeln!(f, " Egraph size: {} nodes, {} classes, {} memo", self.egraph_nodes, self.egraph_classes, self.memo_size)?;
writeln!(f, " Rebuilds: {}", self.rebuilds)?;
writeln!(f, " Total time: {}", self.total_time)?;
writeln!(f, " Search: ({:.2}) {}", self.search_time / self.total_time, self.search_time)?;
writeln!(f, " Apply: ({:.2}) {}", self.apply_time / self.total_time, self.apply_time)?;
writeln!(f, " Rebuild: ({:.2}) {}", self.rebuild_time / self.total_time, self.rebuild_time)?;
Ok(())
}
}

/// Data generated by running a [`Runner`] one iteration.
///
/// If the `serde-1` feature is enabled, this implements
Expand Down Expand Up @@ -375,9 +415,11 @@ where
loop {
let iter = self.run_one(&rules);
self.iterations.push(iter);
if let Some(stop_reason) = &self.iterations.last().unwrap().stop_reason {
let stop_reason = self.iterations.last().unwrap().stop_reason.clone();
// we need to check_limits after the iteration is complete to check for iter_limit
if let Some(stop_reason) = stop_reason.or_else(|| self.check_limits().err()) {
info!("Stopping: {:?}", stop_reason);
self.stop_reason = Some(stop_reason.clone());
self.stop_reason = Some(stop_reason);
break;
}
}
Expand Down Expand Up @@ -430,28 +472,25 @@ where
self.egraph.explain_matches(left, right, subst)
}

#[rustfmt::skip]
/// Prints some information about a runners run.
pub fn print_report(&self) {
let search_time: f64 = self.iterations.iter().map(|i| i.search_time).sum();
let apply_time: f64 = self.iterations.iter().map(|i| i.apply_time).sum();
let rebuild_time: f64 = self.iterations.iter().map(|i| i.rebuild_time).sum();
let total_time: f64 = self.iterations.iter().map(|i| i.total_time).sum();

let iters = self.iterations.len();
let rebuilds: usize = self.iterations.iter().map(|i| i.n_rebuilds).sum();

let eg = &self.egraph;
println!("Runner report");
println!("=============");
println!(" Stop reason: {:?}", self.stop_reason.as_ref().unwrap());
println!(" Iterations: {}", iters);
println!(" Egraph size: {} nodes, {} classes, {} memo", eg.total_number_of_nodes(), eg.number_of_classes(), eg.total_size());
println!(" Rebuilds: {}, {:.2} per iter", rebuilds, (rebuilds as f64) / (iters as f64));
println!(" Total time: {}", total_time);
println!(" Search: ({:.2}) {}", search_time / total_time, search_time);
println!(" Apply: ({:.2}) {}", apply_time / total_time, apply_time);
println!(" Rebuild: ({:.2}) {}", rebuild_time / total_time, rebuild_time);
println!("{}", self.report())
}

/// Creates a [`Report`] summarizing this `Runner`s run.
pub fn report(&self) -> Report {
Report {
stop_reason: self.stop_reason.clone().unwrap(),
iterations: self.iterations.len(),
egraph_nodes: self.egraph.total_number_of_nodes(),
egraph_classes: self.egraph.number_of_classes(),
memo_size: self.egraph.total_size(),
rebuilds: self.iterations.iter().map(|i| i.n_rebuilds).sum(),
search_time: self.iterations.iter().map(|i| i.search_time).sum(),
apply_time: self.iterations.iter().map(|i| i.apply_time).sum(),
rebuild_time: self.iterations.iter().map(|i| i.rebuild_time).sum(),
total_time: self.iterations.iter().map(|i| i.total_time).sum(),
}
}

fn run_one(&mut self, rules: &[&Rewrite<L, N>]) -> Iteration<IterData> {
Expand Down
Loading

0 comments on commit 43efab4

Please sign in to comment.