From 47121fa25cdd91c9ea9350ec9cad3697e67dab17 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Sun, 6 Mar 2022 15:35:58 +0900 Subject: [PATCH] Remove benchmarks for now as it does not work at all. --- Makefile.toml | 17 --- packages/yew/Cargo.toml | 2 - packages/yew/Makefile.toml | 14 --- packages/yew/src/virtual_dom/mod.rs | 187 ---------------------------- 4 files changed, 220 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 56d8503140f..2545218bc8e 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -5,7 +5,6 @@ # * lint # * lint-release # * tests -# * benchmarks # # Run `cargo make --list-all-steps` for more details. # @@ -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 @@ -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" diff --git a/packages/yew/Cargo.toml b/packages/yew/Cargo.toml index fa63c9d84d7..d4bb8dec3d0 100644 --- a/packages/yew/Cargo.toml +++ b/packages/yew/Cargo.toml @@ -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" @@ -80,7 +79,6 @@ trybuild = "1" [features] doc_test = [] wasm_test = [] -wasm_bench = [] ssr = ["futures", "html-escape"] default = [] diff --git a/packages/yew/Makefile.toml b/packages/yew/Makefile.toml index 1a4a0f505e0..6cb68f638c4 100644 --- a/packages/yew/Makefile.toml +++ b/packages/yew/Makefile.toml @@ -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"] diff --git a/packages/yew/src/virtual_dom/mod.rs b/packages/yew/src/virtual_dom/mod.rs index 80e0f82028f..80e85ecaab5 100644 --- a/packages/yew/src/virtual_dom/mod.rs +++ b/packages/yew/src/virtual_dom/mod.rs @@ -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{: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) -> Attributes { - Attributes::Dynamic { - keys: sample_keys(), - values: values.into_iter().map(Some).collect(), - } - } - - fn make_indexed_map(values: Vec) -> 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 { - [ - "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()) - } - } -}