Преглед на файлове

optimize fullstack compile times

Evan Almloff преди 1 година
родител
ревизия
23090cb56b

+ 15 - 21
packages/fullstack/Cargo.toml

@@ -16,18 +16,14 @@ dioxus_server_macro = { workspace = true }
 
 # warp
 warp = { version = "0.3.5", features = ["compression-gzip"], optional = true }
-http-body = { version = "0.4.5", optional = true }
-http-body-util = "0.1.0-rc.2"
 
 # axum
-axum = { version = "0.6.1", features = ["ws", "macros"], optional = true }
+axum = { version = "0.6.1", features = ["ws", "macros"], default-features = false, optional = true }
 tower-http = { version = "0.4.0", optional = true, features = ["fs", "compression-gzip"] }
-tower = { version = "0.4.13", features = ["util"], optional = true }
-axum-macros = "0.3.7"
 
 # salvo
 salvo = { version = "0.46.0", optional = true, features = ["serve-static", "websocket", "compression"] }
-serde = "1.0.159"
+http-body-util = { version = "0.1.0-rc.2", optional = true }
 
 # Dioxus + SSR
 dioxus = { workspace = true }
@@ -45,24 +41,25 @@ dioxus-desktop = { workspace = true, optional = true }
 dioxus-router = { workspace = true, optional = true }
 
 tracing = { workspace = true }
-tracing-futures = { workspace = true }
+tracing-futures = { workspace = true, optional = true }
 once_cell = "1.17.1"
-thiserror = { workspace = true }
-tokio = { workspace = true, features = ["full"], optional = true }
+tokio = { workspace = true, features = ["rt", "sync", "rt-multi-thread"], optional = true }
 tokio-util = { version = "0.7.8", features = ["rt"], optional = true }
-object-pool = "0.5.4"
-anymap = "0.12.1"
+anymap = { version = "0.12.1", optional = true }
 
+serde = "1.0.159"
 serde_json = { version = "1.0.95", optional = true }
 tokio-stream = { version = "0.1.12", features = ["sync"], optional = true }
-futures-util = { workspace = true, optional = true }
-postcard = { version = "1.0.4", features = ["use-std"] }
+futures-util = { workspace = true, default-features = false, optional = true }
+ciborium = "0.2.1"
 base64 = "0.21.0"
 
-pin-project = "1.1.2"
+pin-project = { version = "1.1.2", optional = true }
+thiserror = { workspace = true, optional = true }
 async-trait = "0.1.71"
 bytes = "1.4.0"
-tower-layer = "0.3.2"
+tower = { version = "0.4.13", features = ["util"], optional = true }
+tower-layer = { version = "0.3.2", optional = true }
 
 [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
 dioxus-hot-reload = { workspace = true }
@@ -71,17 +68,14 @@ dioxus-hot-reload = { workspace = true }
 web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
 
 [features]
-default = ["hot-reload", "default-tls"]
+default = ["hot-reload"]
 router = ["dioxus-router"]
 hot-reload = ["serde_json", "futures-util"]
 web = ["dioxus-web"]
 desktop = ["dioxus-desktop"]
 warp = ["dep:warp", "ssr"]
 axum = ["dep:axum", "tower-http", "ssr"]
-salvo = ["dep:salvo", "ssr"]
-ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "dioxus-ssr", "tower", "hyper", "http", "http-body", "dioxus-router/ssr", "tokio-stream"]
+salvo = ["dep:salvo", "ssr", "http-body-util"]
+ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "tokio-stream", "dioxus-ssr", "tower", "hyper", "http", "dioxus-router?/ssr", "tower-layer", "anymap", "tracing-futures", "pin-project", "thiserror"]
 default-tls = ["server_fn/default-tls"]
 rustls = ["server_fn/rustls"]
-
-[dev-dependencies]
-dioxus-fullstack = { path = ".", features = ["router"] }

+ 1 - 2
packages/fullstack/examples/axum-hello-world/Cargo.toml

@@ -9,7 +9,6 @@ publish = false
 [dependencies]
 dioxus = { workspace = true }
 dioxus-fullstack = { workspace = true }
-axum = { version = "0.6.12", optional = true }
 serde = "1.0.159"
 simple_logger = "4.2.0"
 tracing-wasm = "0.2.1"
@@ -19,5 +18,5 @@ reqwest = "0.11.18"
 
 [features]
 default = []
-ssr = ["axum", "dioxus-fullstack/axum"]
+ssr = ["dioxus-fullstack/axum"]
 web = ["dioxus-fullstack/web"]

+ 1 - 2
packages/fullstack/examples/salvo-hello-world/Cargo.toml

@@ -10,7 +10,6 @@ publish = false
 dioxus-web = { workspace = true, features=["hydrate"], optional = true }
 dioxus = { workspace = true }
 dioxus-fullstack = { workspace = true }
-tokio = { workspace = true, features = ["full"], optional = true }
 serde = "1.0.159"
 salvo = { version = "0.37.9", optional = true }
 execute = "0.2.12"
@@ -22,5 +21,5 @@ tracing-subscriber = "0.3.17"
 
 [features]
 default = []
-ssr = ["salvo", "tokio", "dioxus-fullstack/salvo"]
+ssr = ["salvo", "dioxus-fullstack/salvo"]
 web = ["dioxus-web"]

+ 1 - 2
packages/fullstack/examples/warp-hello-world/Cargo.toml

@@ -10,7 +10,6 @@ publish = false
 dioxus-web = { workspace = true, features=["hydrate"], optional = true }
 dioxus = { workspace = true }
 dioxus-fullstack = { workspace = true }
-tokio = { workspace = true, features = ["full"], optional = true }
 serde = "1.0.159"
 warp = { version = "0.3.3", optional = true }
 execute = "0.2.12"
@@ -22,5 +21,5 @@ tracing-subscriber = "0.3.17"
 
 [features]
 default = []
-ssr = ["warp", "tokio", "dioxus-fullstack/warp"]
+ssr = ["warp", "dioxus-fullstack/warp"]
 web = ["dioxus-web"]

+ 1 - 1
packages/fullstack/src/html_storage/deserialize.rs

@@ -15,7 +15,7 @@ pub(crate) fn serde_from_bytes<T: DeserializeOwned>(string: &[u8]) -> Option<T>
         }
     };
 
-    match postcard::from_bytes(&decompressed) {
+    match ciborium::from_reader(std::io::Cursor::new(decompressed)) {
         Ok(data) => Some(data),
         Err(err) => {
             tracing::error!("Failed to deserialize: {}", err);

+ 8 - 5
packages/fullstack/src/html_storage/mod.rs

@@ -1,6 +1,6 @@
 #![allow(unused)]
 
-use std::sync::atomic::AtomicUsize;
+use std::{io::Cursor, sync::atomic::AtomicUsize};
 
 use serde::{de::DeserializeOwned, Serialize};
 
@@ -15,7 +15,8 @@ pub(crate) struct HTMLData {
 
 impl HTMLData {
     pub(crate) fn push<T: Serialize>(&mut self, value: &T) {
-        let serialized = postcard::to_allocvec(value).unwrap();
+        let mut serialized = Vec::new();
+        serialize::serde_to_writable(value, &mut serialized).unwrap();
         self.data.push(serialized);
     }
 
@@ -45,7 +46,7 @@ impl HTMLDataCursor {
         }
         let mut cursor = &self.data[current];
         self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
-        match postcard::from_bytes(cursor) {
+        match ciborium::from_reader(Cursor::new(cursor)) {
             Ok(x) => Some(x),
             Err(e) => {
                 tracing::error!("Error deserializing data: {:?}", e);
@@ -57,7 +58,7 @@ impl HTMLDataCursor {
 
 #[test]
 fn serialized_and_deserializes() {
-    use postcard::to_allocvec;
+    use ciborium::{from_reader, into_writer};
 
     #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
     struct Data {
@@ -97,7 +98,9 @@ fn serialized_and_deserializes() {
                 "original size: {}",
                 std::mem::size_of::<Data>() * data.len()
             );
-            println!("serialized size: {}", to_allocvec(&data).unwrap().len());
+            let mut bytes = Vec::new();
+            into_writer(&data, &mut bytes).unwrap();
+            println!("serialized size: {}", bytes.len());
             println!("compressed size: {}", as_string.len());
 
             let decoded: Vec<Data> = deserialize::serde_from_bytes(&as_string).unwrap();

+ 7 - 6
packages/fullstack/src/html_storage/serialize.rs

@@ -7,8 +7,9 @@ use base64::Engine;
 pub(crate) fn serde_to_writable<T: Serialize>(
     value: &T,
     write_to: &mut impl std::io::Write,
-) -> std::io::Result<()> {
-    let serialized = postcard::to_allocvec(value).unwrap();
+) -> Result<(), ciborium::ser::Error<std::io::Error>> {
+    let mut serialized = Vec::new();
+    ciborium::into_writer(value, &mut serialized)?;
     write_to.write_all(STANDARD.encode(serialized).as_bytes())?;
     Ok(())
 }
@@ -18,12 +19,12 @@ pub(crate) fn serde_to_writable<T: Serialize>(
 pub(crate) fn encode_props_in_element<T: Serialize>(
     data: &T,
     write_to: &mut impl std::io::Write,
-) -> std::io::Result<()> {
+) -> Result<(), ciborium::ser::Error<std::io::Error>> {
     write_to.write_all(
         r#"<meta hidden="true" id="dioxus-storage-props" data-serialized=""#.as_bytes(),
     )?;
     serde_to_writable(data, write_to)?;
-    write_to.write_all(r#"" />"#.as_bytes())
+    Ok(write_to.write_all(r#"" />"#.as_bytes())?)
 }
 
 #[cfg(feature = "ssr")]
@@ -31,10 +32,10 @@ pub(crate) fn encode_props_in_element<T: Serialize>(
 pub(crate) fn encode_in_element(
     data: &super::HTMLData,
     write_to: &mut impl std::io::Write,
-) -> std::io::Result<()> {
+) -> Result<(), ciborium::ser::Error<std::io::Error>> {
     write_to.write_all(
         r#"<meta hidden="true" id="dioxus-storage-data" data-serialized=""#.as_bytes(),
     )?;
     serde_to_writable(&data, write_to)?;
-    write_to.write_all(r#"" />"#.as_bytes())
+    Ok(write_to.write_all(r#"" />"#.as_bytes())?)
 }

+ 6 - 3
packages/fullstack/src/render.rs

@@ -63,7 +63,7 @@ impl SsrRendererPool {
                             }
                             if let Err(err) = renderer.render_to(&mut to, &vdom) {
                                 let _ = tx.send(Err(
-                                    dioxus_router::prelude::IncrementalRendererError::RenderError(
+                                    dioxus_ssr::incremental::IncrementalRendererError::RenderError(
                                         err,
                                     ),
                                 ));
@@ -234,7 +234,9 @@ impl<P: Clone + Serialize + Send + Sync + 'static> dioxus_ssr::incremental::Wrap
         to: &mut R,
     ) -> Result<(), dioxus_ssr::incremental::IncrementalRendererError> {
         // serialize the props
-        crate::html_storage::serialize::encode_props_in_element(&self.cfg.props, to)?;
+        crate::html_storage::serialize::encode_props_in_element(&self.cfg.props, to).map_err(
+            |err| dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(err)),
+        )?;
         // serialize the server state
         crate::html_storage::serialize::encode_in_element(
             &*self.server_context.html_data().map_err(|_| {
@@ -256,7 +258,8 @@ impl<P: Clone + Serialize + Send + Sync + 'static> dioxus_ssr::incremental::Wrap
                 }))
             })?,
             to,
-        )?;
+        )
+        .map_err(|err| dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(err)))?;
 
         #[cfg(all(debug_assertions, feature = "hot-reload"))]
         {

+ 10 - 11
packages/html/Cargo.toml

@@ -19,11 +19,10 @@ euclid = "0.22.7"
 enumset = "1.0.11"
 keyboard-types = "0.7"
 async-trait = "0.1.58"
-serde-value = "0.7.0"
+serde-value = { version = "0.7.0", optional = true }
 tokio = { workspace = true, features = ["fs", "io-util"], optional = true }
 rfd = { version = "0.11.3", optional = true }
-async-channel = "1.8.0"
-serde_json = { version = "1", optional = true }
+serde_json = { version = "1" }
 
 [dependencies.web-sys]
 optional = true
@@ -48,22 +47,22 @@ features = [
 serde_json = "1"
 
 [features]
-default = ["serialize", "mounted"]
+default = ["mounted"]
 serialize = [
     "serde",
     "serde_repr",
-    "serde_json",
     "euclid/serde",
     "keyboard-types/serde",
     "dioxus-core/serialize",
+    "serde-value",
 ]
 mounted = [
-    "web-sys/Element",
-    "web-sys/DomRect",
-    "web-sys/ScrollIntoViewOptions",
-    "web-sys/ScrollLogicalPosition",
-    "web-sys/ScrollBehavior",
-    "web-sys/HtmlElement",
+    "web-sys?/Element",
+    "web-sys?/DomRect",
+    "web-sys?/ScrollIntoViewOptions",
+    "web-sys?/ScrollLogicalPosition",
+    "web-sys?/ScrollBehavior",
+    "web-sys?/HtmlElement",
 ]
 wasm-bind = ["web-sys", "wasm-bindgen"]
 native-bind = ["tokio"]

+ 1 - 4
packages/router/Cargo.toml

@@ -10,13 +10,10 @@ homepage = "https://dioxuslabs.com"
 keywords = ["dom", "ui", "gui", "react", "wasm"]
 
 [dependencies]
-anyhow = "1.0.66"
 dioxus = { workspace = true }
 dioxus-router-macro = { workspace = true }
 gloo = { version = "0.8.0", optional = true }
 tracing = { workspace = true }
-thiserror = { workspace = true }
-futures-util = { workspace = true }
 urlencoding = "2.1.3"
 serde = { version = "1", features = ["derive"], optional = true }
 serde_json = { version = "1.0.91", optional = true }
@@ -36,7 +33,7 @@ default = ["web"]
 ssr = ["dioxus-ssr", "tokio"]
 liveview = ["dioxus-liveview", "tokio", "dep:serde", "serde_json"]
 wasm_test = []
-serde = ["dep:serde", "gloo-utils/serde"]
+serde = ["dep:serde", "gloo-utils?/serde"]
 web = ["gloo", "web-sys", "wasm-bindgen", "gloo-utils", "js-sys"]
 
 [dev-dependencies]

+ 2 - 2
packages/rsx/Cargo.toml

@@ -14,7 +14,7 @@ keywords = ["dom", "ui", "gui", "react"]
 
 [dependencies]
 proc-macro2 = { version = "1.0", features = ["span-locations"] }
-dioxus-core = { workspace = true}
+dioxus-core = { workspace = true, optional = true }
 syn = { version = "2.0", features = ["full", "extra-traits"] }
 quote = { version = "1.0" }
 serde = { version = "1.0", features = ["derive"], optional = true }
@@ -22,5 +22,5 @@ internment = { version = "0.7.0", optional = true }
 krates = { version = "0.12.6", optional = true }
 
 [features]
-hot_reload = ["krates", "internment"]
+hot_reload = ["krates", "internment", "dioxus-core"]
 serde = ["dep:serde"]

+ 2 - 3
packages/ssr/Cargo.toml

@@ -9,18 +9,17 @@ repository = "https://github.com/DioxusLabs/dioxus/"
 keywords = ["dom", "ui", "gui", "react", "ssr"]
 
 [dependencies]
-dioxus-core = { workspace = true, features = ["serialize"] }
+dioxus-core = { workspace = true }
 askama_escape = "0.10.3"
 thiserror = "1.0.23"
 rustc-hash = "1.1.0"
 lru = "0.10.0"
 tracing = { workspace = true }
 http = "0.2.9"
-tokio = { version = "1.28", features = ["full"], optional = true }
+tokio = { version = "1.28", features = ["fs", "io-util"], optional = true }
 
 [dev-dependencies]
 dioxus = { workspace = true }
-thiserror = { workspace = true }
 tracing = { workspace = true }
 fern = { version = "0.6.0", features = ["colored"] }
 anyhow = "1.0"