Merge pull request #1655 from ealmloff/fullstack-binary-size-compile-times

Optimize fullstack compile times
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-01-08 13:33:03 -08:00
commit 6749fd9fe3
12 files changed
+52 -57

No files matched your search

+15 -21
View File
@@ -16,18 +16,14 @@ dioxus_server_macro = { workspace = true }
# warp # warp
warp = { version = "0.3.5", features = ["compression-gzip"], optional = true } 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
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-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
salvo = { version = "0.63.0", optional = true, features = ["serve-static", "websocket", "compression"] } salvo = { version = "0.63.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 + SSR
dioxus = { workspace = true } dioxus = { workspace = true }
@@ -45,24 +41,25 @@ dioxus-desktop = { workspace = true, optional = true }
dioxus-router = { workspace = true, optional = true } dioxus-router = { workspace = true, optional = true }
tracing = { workspace = true } tracing = { workspace = true }
tracing-futures = { workspace = true } tracing-futures = { workspace = true, optional = true }
once_cell = "1.17.1" once_cell = "1.17.1"
thiserror = { workspace = true } tokio = { workspace = true, features = ["rt", "sync", "rt-multi-thread"], optional = true }
tokio = { workspace = true, features = ["full"], optional = true }
tokio-util = { version = "0.7.8", features = ["rt"], optional = true } tokio-util = { version = "0.7.8", features = ["rt"], optional = true }
object-pool = "0.5.4" anymap = { version = "0.12.1", optional = true }
anymap = "0.12.1"
serde = "1.0.159"
serde_json = { version = "1.0.95", optional = true } serde_json = { version = "1.0.95", optional = true }
tokio-stream = { version = "0.1.12", features = ["sync"], optional = true } tokio-stream = { version = "0.1.12", features = ["sync"], optional = true }
futures-util = { workspace = true, optional = true } futures-util = { workspace = true, default-features = false, optional = true }
postcard = { version = "1.0.4", features = ["use-std"] } ciborium = "0.2.1"
base64 = "0.21.0" 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" async-trait = "0.1.71"
bytes = "1.4.0" 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] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
dioxus-hot-reload = { workspace = true } dioxus-hot-reload = { workspace = true }
@@ -75,17 +72,14 @@ web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "Ht
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] } manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] }
[features] [features]
default = ["hot-reload", "default-tls"] default = ["hot-reload"]
router = ["dioxus-router"] router = ["dioxus-router"]
hot-reload = ["serde_json", "futures-util"] hot-reload = ["serde_json", "futures-util"]
web = ["dioxus-web"] web = ["dioxus-web"]
desktop = ["dioxus-desktop"] desktop = ["dioxus-desktop"]
warp = ["dep:warp", "ssr"] warp = ["dep:warp", "ssr"]
axum = ["dep:axum", "tower-http", "ssr"] axum = ["dep:axum", "tower-http", "ssr"]
salvo = ["dep:salvo", "ssr"] salvo = ["dep:salvo", "ssr", "http-body-util"]
ssr = ["server_fn/ssr", "dioxus_server_macro/ssr", "tokio", "tokio-util", "dioxus-ssr", "tower", "hyper", "http", "http-body", "dioxus-router/ssr", "tokio-stream"] 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"] default-tls = ["server_fn/default-tls"]
rustls = ["server_fn/rustls"] rustls = ["server_fn/rustls"]
[dev-dependencies]
dioxus-fullstack = { path = ".", features = ["router"] }
@@ -9,7 +9,6 @@ publish = false
[dependencies] [dependencies]
dioxus = { workspace = true } dioxus = { workspace = true }
dioxus-fullstack = { workspace = true } dioxus-fullstack = { workspace = true }
axum = { version = "0.6.12", optional = true }
serde = "1.0.159" serde = "1.0.159"
simple_logger = "4.2.0" simple_logger = "4.2.0"
tracing-wasm = "0.2.1" tracing-wasm = "0.2.1"
@@ -19,5 +18,5 @@ reqwest = "0.11.18"
[features] [features]
default = [] default = []
ssr = ["axum", "dioxus-fullstack/axum"] ssr = ["dioxus-fullstack/axum"]
web = ["dioxus-fullstack/web"] web = ["dioxus-fullstack/web"]
@@ -10,7 +10,6 @@ publish = false
dioxus-web = { workspace = true, features=["hydrate"], optional = true } dioxus-web = { workspace = true, features=["hydrate"], optional = true }
dioxus = { workspace = true } dioxus = { workspace = true }
dioxus-fullstack = { workspace = true } dioxus-fullstack = { workspace = true }
tokio = { workspace = true, features = ["full"], optional = true }
serde = "1.0.159" serde = "1.0.159"
salvo = { version = "0.63.0", optional = true } salvo = { version = "0.63.0", optional = true }
execute = "0.2.12" execute = "0.2.12"
@@ -22,5 +21,5 @@ tracing-subscriber = "0.3.17"
[features] [features]
default = [] default = []
ssr = ["salvo", "tokio", "dioxus-fullstack/salvo"] ssr = ["salvo", "dioxus-fullstack/salvo"]
web = ["dioxus-web"] web = ["dioxus-web"]
@@ -10,7 +10,6 @@ publish = false
dioxus-web = { workspace = true, features=["hydrate"], optional = true } dioxus-web = { workspace = true, features=["hydrate"], optional = true }
dioxus = { workspace = true } dioxus = { workspace = true }
dioxus-fullstack = { workspace = true } dioxus-fullstack = { workspace = true }
tokio = { workspace = true, features = ["full"], optional = true }
serde = "1.0.159" serde = "1.0.159"
warp = { version = "0.3.3", optional = true } warp = { version = "0.3.3", optional = true }
execute = "0.2.12" execute = "0.2.12"
@@ -22,5 +21,5 @@ tracing-subscriber = "0.3.17"
[features] [features]
default = [] default = []
ssr = ["warp", "tokio", "dioxus-fullstack/warp"] ssr = ["warp", "dioxus-fullstack/warp"]
web = ["dioxus-web"] web = ["dioxus-web"]
@@ -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), Ok(data) => Some(data),
Err(err) => { Err(err) => {
tracing::error!("Failed to deserialize: {}", err); tracing::error!("Failed to deserialize: {}", err);
+8 -5
View File
@@ -1,6 +1,6 @@
#![allow(unused)] #![allow(unused)]
use std::sync::atomic::AtomicUsize; use std::{io::Cursor, sync::atomic::AtomicUsize};
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
@@ -15,7 +15,8 @@ pub(crate) struct HTMLData {
impl HTMLData { impl HTMLData {
pub(crate) fn push<T: Serialize>(&mut self, value: &T) { 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); self.data.push(serialized);
} }
@@ -45,7 +46,7 @@ impl HTMLDataCursor {
} }
let mut cursor = &self.data[current]; let mut cursor = &self.data[current];
self.index.fetch_add(1, std::sync::atomic::Ordering::SeqCst); 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), Ok(x) => Some(x),
Err(e) => { Err(e) => {
tracing::error!("Error deserializing data: {:?}", e); tracing::error!("Error deserializing data: {:?}", e);
@@ -57,7 +58,7 @@ impl HTMLDataCursor {
#[test] #[test]
fn serialized_and_deserializes() { fn serialized_and_deserializes() {
use postcard::to_allocvec; use ciborium::{from_reader, into_writer};
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)] #[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
struct Data { struct Data {
@@ -97,7 +98,9 @@ fn serialized_and_deserializes() {
"original size: {}", "original size: {}",
std::mem::size_of::<Data>() * data.len() 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()); println!("compressed size: {}", as_string.len());
let decoded: Vec<Data> = deserialize::serde_from_bytes(&as_string).unwrap(); let decoded: Vec<Data> = deserialize::serde_from_bytes(&as_string).unwrap();
@@ -7,8 +7,9 @@ use base64::Engine;
pub(crate) fn serde_to_writable<T: Serialize>( pub(crate) fn serde_to_writable<T: Serialize>(
value: &T, value: &T,
write_to: &mut impl std::io::Write, write_to: &mut impl std::io::Write,
) -> std::io::Result<()> { ) -> Result<(), ciborium::ser::Error<std::io::Error>> {
let serialized = postcard::to_allocvec(value).unwrap(); let mut serialized = Vec::new();
ciborium::into_writer(value, &mut serialized)?;
write_to.write_all(STANDARD.encode(serialized).as_bytes())?; write_to.write_all(STANDARD.encode(serialized).as_bytes())?;
Ok(()) Ok(())
} }
@@ -18,12 +19,12 @@ pub(crate) fn serde_to_writable<T: Serialize>(
pub(crate) fn encode_props_in_element<T: Serialize>( pub(crate) fn encode_props_in_element<T: Serialize>(
data: &T, data: &T,
write_to: &mut impl std::io::Write, write_to: &mut impl std::io::Write,
) -> std::io::Result<()> { ) -> Result<(), ciborium::ser::Error<std::io::Error>> {
write_to.write_all( write_to.write_all(
r#"<meta hidden="true" id="dioxus-storage-props" data-serialized=""#.as_bytes(), r#"<meta hidden="true" id="dioxus-storage-props" data-serialized=""#.as_bytes(),
)?; )?;
serde_to_writable(data, write_to)?; serde_to_writable(data, write_to)?;
write_to.write_all(r#"" />"#.as_bytes()) Ok(write_to.write_all(r#"" />"#.as_bytes())?)
} }
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
@@ -31,10 +32,10 @@ pub(crate) fn encode_props_in_element<T: Serialize>(
pub(crate) fn encode_in_element( pub(crate) fn encode_in_element(
data: &super::HTMLData, data: &super::HTMLData,
write_to: &mut impl std::io::Write, write_to: &mut impl std::io::Write,
) -> std::io::Result<()> { ) -> Result<(), ciborium::ser::Error<std::io::Error>> {
write_to.write_all( write_to.write_all(
r#"<meta hidden="true" id="dioxus-storage-data" data-serialized=""#.as_bytes(), r#"<meta hidden="true" id="dioxus-storage-data" data-serialized=""#.as_bytes(),
)?; )?;
serde_to_writable(&data, write_to)?; serde_to_writable(&data, write_to)?;
write_to.write_all(r#"" />"#.as_bytes()) Ok(write_to.write_all(r#"" />"#.as_bytes())?)
} }
+6 -3
View File
@@ -65,7 +65,7 @@ impl SsrRendererPool {
} }
if let Err(err) = renderer.render_to(&mut to, &vdom) { if let Err(err) = renderer.render_to(&mut to, &vdom) {
let _ = tx.send(Err( let _ = tx.send(Err(
dioxus_router::prelude::IncrementalRendererError::RenderError( dioxus_ssr::incremental::IncrementalRendererError::RenderError(
err, err,
), ),
)); ));
@@ -236,7 +236,9 @@ impl<P: Clone + Serialize + Send + Sync + 'static> dioxus_ssr::incremental::Wrap
to: &mut R, to: &mut R,
) -> Result<(), dioxus_ssr::incremental::IncrementalRendererError> { ) -> Result<(), dioxus_ssr::incremental::IncrementalRendererError> {
// serialize the props // 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 // serialize the server state
crate::html_storage::serialize::encode_in_element( crate::html_storage::serialize::encode_in_element(
&*self.server_context.html_data().map_err(|_| { &*self.server_context.html_data().map_err(|_| {
@@ -258,7 +260,8 @@ impl<P: Clone + Serialize + Send + Sync + 'static> dioxus_ssr::incremental::Wrap
})) }))
})?, })?,
to, to,
)?; )
.map_err(|err| dioxus_ssr::incremental::IncrementalRendererError::Other(Box::new(err)))?;
#[cfg(all(debug_assertions, feature = "hot-reload"))] #[cfg(all(debug_assertions, feature = "hot-reload"))]
{ {
+8 -7
View File
@@ -20,7 +20,7 @@ euclid = "0.22.7"
enumset = "1.1.2" enumset = "1.1.2"
keyboard-types = "0.7" keyboard-types = "0.7"
async-trait = "0.1.58" 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 } tokio = { workspace = true, features = ["fs", "io-util"], optional = true }
rfd = { version = "0.12", optional = true } rfd = { version = "0.12", optional = true }
async-channel = "1.8.0" async-channel = "1.8.0"
@@ -55,14 +55,15 @@ serialize = [
"euclid/serde", "euclid/serde",
"keyboard-types/serde", "keyboard-types/serde",
"dioxus-core/serialize", "dioxus-core/serialize",
"serde-value",
] ]
mounted = [ mounted = [
"web-sys/Element", "web-sys?/Element",
"web-sys/DomRect", "web-sys?/DomRect",
"web-sys/ScrollIntoViewOptions", "web-sys?/ScrollIntoViewOptions",
"web-sys/ScrollLogicalPosition", "web-sys?/ScrollLogicalPosition",
"web-sys/ScrollBehavior", "web-sys?/ScrollBehavior",
"web-sys/HtmlElement", "web-sys?/HtmlElement",
] ]
eval = [ eval = [
"serde", "serde",
+1 -4
View File
@@ -10,13 +10,10 @@ homepage = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react", "wasm"] keywords = ["dom", "ui", "gui", "react", "wasm"]
[dependencies] [dependencies]
anyhow = "1.0.66"
dioxus = { workspace = true } dioxus = { workspace = true }
dioxus-router-macro = { workspace = true } dioxus-router-macro = { workspace = true }
gloo = { version = "0.8.0", optional = true } gloo = { version = "0.8.0", optional = true }
tracing = { workspace = true } tracing = { workspace = true }
thiserror = { workspace = true }
futures-util = { workspace = true }
urlencoding = "2.1.3" urlencoding = "2.1.3"
serde = { version = "1", features = ["derive"], optional = true } serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1.0.91", optional = true } serde_json = { version = "1.0.91", optional = true }
@@ -36,7 +33,7 @@ default = ["web"]
ssr = ["dioxus-ssr", "tokio"] ssr = ["dioxus-ssr", "tokio"]
liveview = ["dioxus-liveview", "tokio", "dep:serde", "serde_json"] liveview = ["dioxus-liveview", "tokio", "dep:serde", "serde_json"]
wasm_test = [] wasm_test = []
serde = ["dep:serde", "gloo-utils/serde"] serde = ["dep:serde", "gloo-utils?/serde"]
web = ["gloo", "web-sys", "wasm-bindgen", "gloo-utils", "js-sys"] web = ["gloo", "web-sys", "wasm-bindgen", "gloo-utils", "js-sys"]
[dev-dependencies] [dev-dependencies]
+2 -2
View File
@@ -14,7 +14,7 @@ keywords = ["dom", "ui", "gui", "react"]
[dependencies] [dependencies]
proc-macro2 = { version = "1.0", features = ["span-locations"] } 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"] } syn = { version = "2.0", features = ["full", "extra-traits"] }
quote = { version = "1.0" } quote = { version = "1.0" }
serde = { version = "1.0", features = ["derive"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true }
@@ -24,6 +24,6 @@ tracing.workspace = true
[features] [features]
default = ["html"] default = ["html"]
hot_reload = ["krates", "internment"] hot_reload = ["krates", "internment", "dioxus-core"]
serde = ["dep:serde"] serde = ["dep:serde"]
html = [] html = []
+1 -2
View File
@@ -17,13 +17,12 @@ rustc-hash = "1.1.0"
lru = "0.10.0" lru = "0.10.0"
tracing = { workspace = true } tracing = { workspace = true }
http = "0.2.9" http = "0.2.9"
tokio = { version = "1.28", features = ["full"], optional = true } tokio = { version = "1.28", features = ["fs", "io-util"], optional = true }
async-trait = "0.1.58" async-trait = "0.1.58"
serde_json = { version = "1.0" } serde_json = { version = "1.0" }
[dev-dependencies] [dev-dependencies]
dioxus = { workspace = true } dioxus = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
fern = { version = "0.6.0", features = ["colored"] } fern = { version = "0.6.0", features = ["colored"] }
anyhow = "1.0" anyhow = "1.0"