Skip to content

Commit

Permalink
Remove benchmarks for now as it does not work at all. (#2495)
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Mar 7, 2022
1 parent dce04f1 commit f39afdc
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 220 deletions.
17 changes: 0 additions & 17 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# * lint
# * lint-release
# * tests
# * benchmarks
#
# Run `cargo make --list-all-steps` for more details.
#
Expand Down Expand Up @@ -40,12 +39,6 @@ dependencies = ["tests-setup"]
env = { CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = ["**/examples/*", "**/packages/changelog"] }
run_task = { name = ["test-flow", "doc-test-flow", "ssr-test", "website-test"], fork = true }

[tasks.benchmarks]
category = "Testing"
description = "Run benchmarks"
env = { CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = ["**/examples/*"] }
run_task = { name = "bench-flow", fork = true }

[tasks.lint-flow]
private = true
workspace = true
Expand Down Expand Up @@ -98,16 +91,6 @@ args = ["test", "--doc"]
command = "cargo"
args = ["test", "-p", "website-test"]

[tasks.bench-flow]
private = true
workspace = true
dependencies = ["bench"]

[tasks.bench]
private = true
command = "cargo"
args = ["bench"]

[tasks.generate-change-log]
category = "Maintainer processes"
toolchain = "stable"
Expand Down
2 changes: 0 additions & 2 deletions packages/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ wasm-bindgen-futures = "0.4"
tokio = { version = "1.15.0", features = ["rt"], optional = true }

[dev-dependencies]
easybench-wasm = "0.2"
wasm-bindgen-test = "0.3"
gloo = { version = "0.6", features = ["futures"] }
wasm-bindgen-futures = "0.4"
Expand All @@ -80,7 +79,6 @@ trybuild = "1"
[features]
doc_test = []
wasm_test = []
wasm_bench = []
ssr = ["futures", "html-escape"]
default = []

Expand Down
14 changes: 0 additions & 14 deletions packages/yew/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ args = [
"doc_test,wasm_test",
]

[tasks.bench]
extend = "core::wasm-pack-base"
command = "wasm-pack"
args = [
"test",
"--release",
"--firefox",
"--headless",
"--",
"--features",
"wasm_bench",
"bench",
]

[tasks.ssr-test]
command = "cargo"
args = ["test", "ssr_tests", "--features", "ssr"]
187 changes: 0 additions & 187 deletions packages/yew/src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,190 +270,3 @@ impl Default for Attributes {
Self::Static(&[])
}
}

#[cfg(all(test, feature = "wasm_bench"))]
mod benchmarks {
use super::*;
use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure};

wasm_bindgen_test_configure!(run_in_browser);

macro_rules! run {
($name:ident => {
$( $old:expr => $new:expr )+
}) => {
// NB: these benchmarks only compare diffing. They do not take into account aspects like
// allocation impact, which is lower for both `Static` and `Dynamic`.

let results = vec![
$(
{
let mut old = $old.clone();
let new = $new.clone();
let el = gloo_utils::document().create_element("div").unwrap();
old.apply(&el);
(
format!("{} -> {}", attr_variant(&old), attr_variant(&new)),
easybench_wasm::bench_env_limit(
2.0,
(NodeCloner(el), new, old),
|(el, mut new, old)| new.apply_diff(&el.0, old),
),
)
},
)+
];

let max_name_len = results.iter().map(|(name, _)| name.len()).max().unwrap_or_default();
wasm_bindgen_test::console_log!(
"{}:{}",
stringify!($name),
results.into_iter().fold(String::new(), |mut acc, (name, res)| {
use std::fmt::Write;

write!(&mut acc, "\n\t\t{:<width$}: ", name, width=max_name_len).unwrap();

if res.ns_per_iter.is_nan() {
acc += "benchmark too slow to produce meaningful results";
} else {
write!(
&mut acc,
"{:>7.4} ns (R²={:.3}, {:>7} iterations in {:>3} samples)",
res.ns_per_iter,
res.goodness_of_fit,
res.iterations,
res.samples,
)
.unwrap();
}

acc
})
);
};
}

#[wasm_bindgen_test]
fn bench_diff_empty() {
let static_ = Attributes::Static(&[]);
let dynamic = Attributes::Dynamic {
keys: &[],
values: Box::new([]),
};
let map = Attributes::IndexMap(Default::default());

run! {
empty => {
static_ => static_
dynamic => dynamic
map => map
static_ => dynamic
static_ => map
dynamic => map
}
}
}

#[wasm_bindgen_test]
fn bench_diff_equal() {
let static_ = Attributes::Static(sample_attrs());
let dynamic = make_dynamic(sample_values());
let map = make_indexed_map(sample_values());

run! {
equal => {
static_ => static_
dynamic => dynamic
map => map
static_ => dynamic
static_ => map
dynamic => map
}
}
}

#[wasm_bindgen_test]
fn bench_diff_change_first() {
let old = sample_values();
let mut new = old.clone();
new[0] = AttrValue::Static("changed");

let dynamic = (make_dynamic(old.clone()), make_dynamic(new.clone()));
let map = (make_indexed_map(old), make_indexed_map(new));

run! {
changed_first => {
dynamic.0 => dynamic.1
map.0 => map.1
dynamic.0 => map.1
}
}
}

fn make_dynamic(values: Vec<AttrValue>) -> Attributes {
Attributes::Dynamic {
keys: sample_keys(),
values: values.into_iter().map(Some).collect(),
}
}

fn make_indexed_map(values: Vec<AttrValue>) -> Attributes {
Attributes::IndexMap(
sample_keys()
.iter()
.copied()
.zip(values.into_iter())
.collect(),
)
}

fn sample_keys() -> &'static [&'static str] {
&[
"oh", "boy", "pipes", "are", "from", "to", "and", "the", "side",
]
}

fn sample_values() -> Vec<AttrValue> {
[
"danny", "the", "the", "calling", "glen", "glen", "down", "mountain", "",
]
.iter()
.map(|v| AttrValue::Static(*v))
.collect()
}

fn sample_attrs() -> &'static [[&'static str; 2]] {
&[
["oh", "danny"],
["boy", "the"],
["pipes", "the"],
["are", "calling"],
["from", "glen"],
["to", "glen"],
["and", "down"],
["the", "mountain"],
["side", ""],
]
}

fn attr_variant(attrs: &Attributes) -> &'static str {
use Attributes::*;

match attrs {
Static(_) => "static",
Dynamic { .. } => "dynamic",
IndexMap(_) => "indexed_map",
}
}

/// Clones the node on [Clone] call
struct NodeCloner(Element);

impl Clone for NodeCloner {
fn clone(&self) -> Self {
use wasm_bindgen::JsCast;

Self(self.0.clone_node().unwrap().dyn_into().unwrap())
}
}
}

1 comment on commit f39afdc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: f39afdc Previous: dce04f1 Ratio
yew-struct-keyed 01_run1k 194.273 195.7005 0.99
yew-struct-keyed 02_replace1k 216.666 214.3865 1.01
yew-struct-keyed 03_update10th1k_x16 405.52 396.161 1.02
yew-struct-keyed 04_select1k 87.868 77.089 1.14
yew-struct-keyed 05_swap1k 104.7975 95.467 1.10
yew-struct-keyed 06_remove-one-1k 32.0875 31.6645 1.01
yew-struct-keyed 07_create10k 2382.675 2276.3230000000003 1.05
yew-struct-keyed 08_create1k-after1k_x2 447.3825 416.014 1.08
yew-struct-keyed 09_clear1k_x8 161.01850000000002 227.319 0.71
yew-struct-keyed 21_ready-memory 0.9634475708007812 0.9634475708007812 1
yew-struct-keyed 22_run-memory 1.4578819274902344 1.4578819274902344 1
yew-struct-keyed 23_update5-memory 1.4616203308105469 1.473674774169922 0.99
yew-struct-keyed 24_run5-memory 1.5110588073730469 1.5059242248535156 1.00
yew-struct-keyed 25_run-clear-memory 1.128643035888672 1.1257438659667969 1.00
yew-struct-keyed 31_startup-ci 1769.9440000000002 1731.1440000000002 1.02
yew-struct-keyed 32_startup-bt 35.621999999999986 38.469999999999985 0.93
yew-struct-keyed 34_startup-totalbytes 359.8974609375 359.8974609375 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.