on master help sign in
Use FxHashMap for faster hashing of cached strings
commit635ae83afcd878359457f8394705a864d257d683 authorTill Schneidereit <till@tillschneidereit.net> dateMon 11 Mar 2019, 12:05 (8 years ago) parentd470c3d
3 files changed+31−12
Cargo.lock+26−8 Cargo.toml+1 src/change_list.rs+4−4
Cargo.lock+26−8
@@ -1,3 +1,5 @@
1+# This file is automatically @generated by Cargo.
2+# It is not intended for manual editing.
13[[package]]
24name = "aho-corasick"
35version = "0.6.10"
@@ -48,6 +50,11 @@ name = "bumpalo"
4850version = "2.1.0"
4951source = "registry+https://github.com/rust-lang/crates.io-index"
5052
53+[[package]]
54+name = "byteorder"
55+version = "1.3.1"
56+source = "registry+https://github.com/rust-lang/crates.io-index"
57+
5158[[package]]
5259name = "cc"
5360version = "1.0.30"
@@ -85,6 +92,7 @@ dependencies = [
8592 "console_log 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
8693 "dodrio-js-api 0.1.0",
8794 "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
95+ "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
8896 "js-sys 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
8997 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
9098 "wasm-bindgen 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -230,7 +238,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
230238dependencies = [
231239 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
232240 "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
233− "syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)",
241+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
234242 "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
235243]
236244
@@ -239,6 +247,14 @@ name = "futures"
239247version = "0.1.25"
240248source = "registry+https://github.com/rust-lang/crates.io-index"
241249
250+[[package]]
251+name = "fxhash"
252+version = "0.2.1"
253+source = "registry+https://github.com/rust-lang/crates.io-index"
254+dependencies = [
255+ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
256+]
257+
242258[[package]]
243259name = "heck"
244260version = "0.3.1"
@@ -384,7 +400,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
384400dependencies = [
385401 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
386402 "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
387− "syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)",
403+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
388404]
389405
390406[[package]]
@@ -404,7 +420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
404420
405421[[package]]
406422name = "syn"
407−version = "0.15.28"
423+version = "0.15.29"
408424source = "registry+https://github.com/rust-lang/crates.io-index"
409425dependencies = [
410426 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -419,7 +435,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
419435dependencies = [
420436 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
421437 "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
422− "syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)",
438+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
423439 "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
424440]
425441
@@ -491,7 +507,7 @@ dependencies = [
491507 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
492508 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
493509 "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
494− "syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)",
510+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
495511 "wasm-bindgen-shared 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
496512]
497513
@@ -521,7 +537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
521537dependencies = [
522538 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
523539 "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
524− "syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)",
540+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
525541 "wasm-bindgen-backend 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
526542 "wasm-bindgen-shared 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
527543]
@@ -564,7 +580,7 @@ dependencies = [
564580 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
565581 "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
566582 "quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
567− "syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)",
583+ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)",
568584 "wasm-bindgen-backend 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
569585 "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
570586]
@@ -633,6 +649,7 @@ dependencies = [
633649"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4"
634650"checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6"
635651"checksum bumpalo 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "21ef2109240a377370f55ea3ef0b486b46d7b5c0f7455ab0ec676d73f875d58a"
652+"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb"
636653"checksum cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "d01c69d08ff207f231f07196e30f84c70f1c815b04f980f8b7b01ff01f05eb92"
637654"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4"
638655"checksum console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
@@ -641,6 +658,7 @@ dependencies = [
641658"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
642659"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
643660"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
661+"checksum fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
644662"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
645663"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
646664"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
@@ -664,7 +682,7 @@ dependencies = [
664682"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c"
665683"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d"
666684"checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3"
667−"checksum syn 0.15.28 (registry+https://github.com/rust-lang/crates.io-index)" = "218aa5a01ab9805df6e9e48074c8d88f317cc9660b1ad6c3dabac2d627d185d6"
685+"checksum syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1825685f977249735d510a242a6727b46efe914bb67e38d30c071b1b72b1d5c2"
668686"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
669687"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f"
670688"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
Cargo.toml+1
@@ -11,6 +11,7 @@ futures = "0.1.25"
1111wasm-bindgen = "0.2.38"
1212wasm-bindgen-futures = "0.3.15"
1313js-sys = "0.3.15"
14+fxhash = "0.2.1"
1415log = { version = "0.4.6", optional = true }
1516
1617[dependencies.web-sys]
src/change_list.rs+4−4
@@ -1,7 +1,7 @@
11use crate::Listener;
22use bumpalo::Bump;
33use std::cell::Cell;
4−use std::collections::HashMap;
4+use fxhash::FxHashMap;
55use std::fmt;
66use std::sync::Once;
77use wasm_bindgen::prelude::*;
@@ -41,7 +41,7 @@ struct StringsCacheEntry {
4141
4242pub(crate) struct ChangeList {
4343 bump: Bump,
44− strings_cache: HashMap<String, StringsCacheEntry>,
44+ strings_cache: FxHashMap<String, StringsCacheEntry>,
4545 next_string_key: Cell<u32>,
4646 js: js::ChangeList,
4747 events_trampoline: Option<Closure<Fn(web_sys::Event, u32, u32)>>,
@@ -78,7 +78,7 @@ impl ChangeList {
7878 });
7979
8080 let bump = Bump::new();
81− let strings_cache = HashMap::new();
81+ let strings_cache = FxHashMap::default();
8282 let js = js::ChangeList::new(container);
8383 ChangeList {
8484 bump,
@@ -321,7 +321,7 @@ impl ChangeList {
321321
322322 pub(crate) fn drop_unused_strings(&mut self) {
323323 debug!("drop_unused_strings()");
324− let mut new_cache = HashMap::new();
324+ let mut new_cache = FxHashMap::default();
325325 for (key, val) in self.strings_cache.iter() {
326326 if val.used {
327327 new_cache.insert(key.clone(), StringsCacheEntry { key: val.key, used: false });