Skip to content

Commit

Permalink
Migrate to once_cell (#2750)
Browse files Browse the repository at this point in the history
* Replace lazy_static with once_cell.

* Migrate to clap v3, so 1 less lazy_static.

* Convert with `.into()`.
  • Loading branch information
futursolo committed Jun 24, 2022
1 parent 54de041 commit 6b89e21
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 188 deletions.
2 changes: 1 addition & 1 deletion examples/function_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ rand = { version = "0.8", features = ["small_rng"] }
yew = { path = "../../packages/yew" }
yew-router = { path = "../../packages/yew-router" }
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
gloo-timers = "0.2"
wasm-logger = "0.2"
instant = { version = "0.1", features = ["wasm-bindgen"] }
once_cell = "1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand Down
14 changes: 6 additions & 8 deletions examples/function_router/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use lazy_static::lazy_static;
use lipsum::MarkovChain;
use once_cell::sync::Lazy;
use rand::distributions::Bernoulli;
use rand::rngs::StdRng;
use rand::seq::IteratorRandom;
Expand All @@ -9,13 +9,11 @@ const KEYWORDS: &str = include_str!("../data/keywords.txt");
const SYLLABLES: &str = include_str!("../data/syllables.txt");
const YEW_CONTENT: &str = include_str!("../data/yew.txt");

lazy_static! {
static ref YEW_CHAIN: MarkovChain<'static> = {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
};
}
static YEW_CHAIN: Lazy<MarkovChain<'static>> = Lazy::new(|| {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
});

pub struct Generator {
pub seed: u32,
Expand Down
2 changes: 1 addition & 1 deletion examples/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ wasm-logger = "0.2"
yew = { path = "../../packages/yew", features = ["csr"] }
yew-router = { path = "../../packages/yew-router" }
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
once_cell = "1"
gloo-timers = "0.2"
14 changes: 6 additions & 8 deletions examples/router/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use lazy_static::lazy_static;
use lipsum::MarkovChain;
use once_cell::sync::Lazy;
use rand::distributions::Bernoulli;
use rand::rngs::SmallRng;
use rand::seq::IteratorRandom;
Expand All @@ -9,13 +9,11 @@ const KEYWORDS: &str = include_str!("../data/keywords.txt");
const SYLLABLES: &str = include_str!("../data/syllables.txt");
const YEW_CONTENT: &str = include_str!("../data/yew.txt");

lazy_static! {
static ref YEW_CHAIN: MarkovChain<'static> = {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
};
}
static YEW_CHAIN: Lazy<MarkovChain<'static>> = Lazy::new(|| {
let mut chain = MarkovChain::new();
chain.learn(YEW_CONTENT);
chain
});

pub struct Generator {
pub seed: u64,
Expand Down
1 change: 0 additions & 1 deletion packages/yew-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ proc-macro = true

[dependencies]
boolinator = "2"
lazy_static = "1"
proc-macro-error = "1"
proc-macro2 = "1"
quote = "1"
Expand Down
294 changes: 143 additions & 151 deletions packages/yew-macro/src/props/element.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;

use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use syn::parse::{Parse, ParseStream};
use syn::{Expr, ExprTuple};

Expand Down Expand Up @@ -64,154 +64,146 @@ impl Parse for ElementProps {
}
}

lazy_static! {
static ref BOOLEAN_SET: HashSet<&'static str> = {
vec![
// Living Standard
// From: https://html.spec.whatwg.org/#attributes-3
// where `Value` = Boolean attribute
// Note: `checked` is uniquely handled in the html! macro.
"allowfullscreen",
"async",
"autofocus",
"autoplay",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
]
.into_iter()
.collect()
};
}

lazy_static! {
static ref LISTENER_SET: HashSet<&'static str> = {
vec![
// Living Standard
// From: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
"onabort",
"onauxclick",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
// onfocusin + onfocusout not in standard but added due to browser support
// see issue 1896: https://github.com/yewstack/yew/issues/1896
"onfocusin",
"onfocusout",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onslotchange",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwheel",
static BOOLEAN_SET: Lazy<HashSet<&'static str>> = Lazy::new(|| {
[
// Living Standard
// From: https://html.spec.whatwg.org/#attributes-3
// where `Value` = Boolean attribute
// Note: `checked` is uniquely handled in the html! macro.
"allowfullscreen",
"async",
"autofocus",
"autoplay",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
]
.into()
});

// Standard HTML Document and Element
// From: https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers
"oncopy",
"oncut",
"onpaste",

// Others
// From: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
"onanimationcancel",
"onanimationend",
"onanimationiteration",
"onanimationstart",
"ongotpointercapture",
"onloadend",
"onlostpointercapture",
"onpointercancel",
"onpointerdown",
"onpointerenter",
"onpointerleave",
"onpointerlockchange",
"onpointerlockerror",
"onpointermove",
"onpointerout",
"onpointerover",
"onpointerup",
"onselectionchange",
"onselectstart",
"onshow",
"ontouchcancel",
"ontouchend",
"ontouchmove",
"ontouchstart",
"ontransitioncancel",
"ontransitionend",
"ontransitionrun",
"ontransitionstart",
]
.into_iter()
.collect()
};
}
static LISTENER_SET: Lazy<HashSet<&'static str>> = Lazy::new(|| {
[
// Living Standard
// From: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
"onabort",
"onauxclick",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
// onfocusin + onfocusout not in standard but added due to browser support
// see issue 1896: https://github.com/yewstack/yew/issues/1896
"onfocusin",
"onfocusout",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onslotchange",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwheel",
// Standard HTML Document and Element
// From: https://html.spec.whatwg.org/multipage/webappapis.html#documentandelementeventhandlers
"oncopy",
"oncut",
"onpaste",
// Others
// From: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers
"onanimationcancel",
"onanimationend",
"onanimationiteration",
"onanimationstart",
"ongotpointercapture",
"onloadend",
"onlostpointercapture",
"onpointercancel",
"onpointerdown",
"onpointerenter",
"onpointerleave",
"onpointerlockchange",
"onpointerlockerror",
"onpointermove",
"onpointerout",
"onpointerover",
"onpointerup",
"onselectionchange",
"onselectstart",
"onshow",
"ontouchcancel",
"ontouchend",
"ontouchmove",
"ontouchstart",
"ontransitioncancel",
"ontransitionend",
"ontransitionrun",
"ontransitionstart",
]
.into()
});
4 changes: 2 additions & 2 deletions tools/changelog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ git2 = "=0.14.2" # see https://github.com/rust-lang/git2-rs/issues/838 fixed wit
regex = "1"
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = { version = "1", features = ["derive"] }
structopt = "0.3"
strum = { version = "0.24", features = ["derive"] }
lazy_static = "1.4.0"
clap = { version = "3", features = ["derive"] }
semver = "1.0"
once_cell = "1"

1 comment on commit 6b89e21

@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: 6b89e21 Previous: 54de041 Ratio
yew-struct-keyed 01_run1k 153.958 217.9235 0.71
yew-struct-keyed 02_replace1k 160.041 227.757 0.70
yew-struct-keyed 03_update10th1k_x16 265.0145 429.3715 0.62
yew-struct-keyed 04_select1k 39.68 81.12899999999999 0.49
yew-struct-keyed 05_swap1k 64.8015 118.495 0.55
yew-struct-keyed 06_remove-one-1k 24.304 41.1275 0.59
yew-struct-keyed 07_create10k 2573.5415000000003 3746.5375 0.69
yew-struct-keyed 08_create1k-after1k_x2 343.18 492.5535 0.70
yew-struct-keyed 09_clear1k_x8 145.0945 218.489 0.66
yew-struct-keyed 21_ready-memory 1.4694786071777344 1.4694786071777344 1
yew-struct-keyed 22_run-memory 1.6625480651855469 1.6632156372070312 1.00
yew-struct-keyed 23_update5-memory 1.6997566223144531 1.6996002197265625 1.00
yew-struct-keyed 24_run5-memory 1.7159767150878906 1.862407684326172 0.92
yew-struct-keyed 25_run-clear-memory 1.3307838439941406 1.3292884826660156 1.00
yew-struct-keyed 31_startup-ci 1880.825 1732.7759999999998 1.09
yew-struct-keyed 32_startup-bt 41.67199999999998 44.828 0.93
yew-struct-keyed 33_startup-mainthreadcost 192.8 276.84799999999996 0.70
yew-struct-keyed 34_startup-totalbytes 332.2724609375 332.2724609375 1

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

Please sign in to comment.