perf: remove global allocation for props
This commit is contained in:
1 parent
369b36b2c6
commit
8b3ac0b57c
15 files changed
+352
-105
No files matched your search
@@ -3,7 +3,7 @@
|
||||
/// We intern all the HTML tags and attributes, making most operations much faster.
|
||||
///
|
||||
/// Interning takes about 1ms at the start of the app, but saves a *ton* of time later on.
|
||||
pub fn intern_cache() {
|
||||
pub fn intern_cached_strings() {
|
||||
let cached_words = [
|
||||
// All the HTML Tags
|
||||
"a",
|
||||
@@ -222,13 +222,11 @@ pub fn intern_cache() {
|
||||
"onmousewheel",
|
||||
"onoffline",
|
||||
"ononline",
|
||||
"<body>",
|
||||
"onpageshow",
|
||||
"onpaste",
|
||||
"onpause",
|
||||
"onplay",
|
||||
"onplaying",
|
||||
"<body>",
|
||||
"onprogress",
|
||||
"onratechange",
|
||||
"onreset",
|
||||
@@ -239,7 +237,6 @@ pub fn intern_cache() {
|
||||
"onseeking",
|
||||
"onselect",
|
||||
"onstalled",
|
||||
"<body>",
|
||||
"onsubmit",
|
||||
"onsuspend",
|
||||
"ontimeupdate",
|
||||
@@ -284,6 +281,21 @@ pub fn intern_cache() {
|
||||
"value",
|
||||
"width",
|
||||
"wrap",
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
];
|
||||
|
||||
for s in cached_words {
|
||||
|
||||
+11
-5
@@ -56,7 +56,7 @@ use std::rc::Rc;
|
||||
|
||||
pub use crate::cfg::WebConfig;
|
||||
use crate::dom::load_document;
|
||||
use cache::intern_cache;
|
||||
use cache::intern_cached_strings;
|
||||
use dioxus::prelude::Properties;
|
||||
use dioxus::virtual_dom::VirtualDom;
|
||||
pub use dioxus_core as dioxus;
|
||||
@@ -115,7 +115,7 @@ where
|
||||
pub async fn run_with_props<T: Properties + 'static>(root: FC<T>, root_props: T, cfg: WebConfig) {
|
||||
let mut dom = VirtualDom::new_with_props(root, root_props);
|
||||
|
||||
intern_cache();
|
||||
intern_cached_strings();
|
||||
|
||||
let hydrating = cfg.hydrate;
|
||||
|
||||
@@ -134,16 +134,22 @@ pub async fn run_with_props<T: Properties + 'static>(root: FC<T>, root_props: T,
|
||||
}
|
||||
|
||||
let work_loop = ric_raf::RafLoop::new();
|
||||
|
||||
loop {
|
||||
// if virtualdom has nothing, wait for it to have something before requesting idle time
|
||||
if !dom.has_work() {
|
||||
dom.wait_for_any_work().await;
|
||||
}
|
||||
// if there is work then this future resolves immediately.
|
||||
dom.wait_for_work().await;
|
||||
|
||||
// wait for the mainthread to schedule us in
|
||||
let deadline = work_loop.wait_for_idle_time().await;
|
||||
|
||||
// run the virtualdom work phase until the frame deadline is reached
|
||||
let mut mutations = dom.run_with_deadline(deadline).await;
|
||||
|
||||
// wait for the animation frame to fire so we can apply our changes
|
||||
work_loop.wait_for_raf().await;
|
||||
|
||||
// actually apply our changes during the animation frame
|
||||
websys_dom.process_edits(&mut mutations[0].edits);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user