wip: nail down some cache thrashing issues

This commit is contained in:
Jonathan Kelley 2024-12-03 13:55:38 -08:00
parent 1a30a2f75f
commit b65c74f93c
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
11 changed files with 88 additions and 112 deletions

46
Cargo.lock generated
View file

@ -3521,7 +3521,7 @@ dependencies = [
"unicode-segmentation",
"uuid",
"walkdir",
"walrus 0.22.0",
"walrus",
"wasm-bindgen-cli-support",
"wasm-bindgen-shared",
"wasm-opt",
@ -3530,9 +3530,6 @@ dependencies = [
[[package]]
name = "dioxus-cli-config"
version = "0.6.0-rc.0"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "dioxus-cli-opt"
@ -14802,23 +14799,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "walrus"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d68aa3c7b80be75c8458fc087453e5a31a226cfffede2e9b932393b2ea1c624a"
dependencies = [
"anyhow",
"gimli 0.26.2",
"id-arena",
"leb128",
"log",
"rayon",
"walrus-macro",
"wasm-encoder 0.212.0",
"wasmparser 0.212.0",
]
[[package]]
name = "walrus"
version = "0.23.1"
@ -14830,8 +14810,9 @@ dependencies = [
"id-arena",
"leb128",
"log",
"rayon",
"walrus-macro",
"wasm-encoder 0.214.0",
"wasm-encoder",
"wasmparser 0.214.0",
]
@ -14936,7 +14917,7 @@ dependencies = [
"serde_json",
"tempfile",
"unicode-ident",
"walrus 0.23.1",
"walrus",
"wasm-bindgen-externref-xform",
"wasm-bindgen-multi-value-xform",
"wasm-bindgen-shared",
@ -14952,7 +14933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e18f2b3830afd01899e1f3252bd310c52eb4e76aae8ee406de26ade3ce80618c"
dependencies = [
"anyhow",
"walrus 0.23.1",
"walrus",
"wasm-bindgen-wasm-conventions",
]
@ -14999,7 +14980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "688e1343d8220793ed018c6d516ab782708e7550152f36f089adde39f69eef5a"
dependencies = [
"anyhow",
"walrus 0.23.1",
"walrus",
"wasm-bindgen-wasm-conventions",
]
@ -15042,7 +15023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa429167b4fe4155e91343b31dba3e8fbd07bcc70bf26d44fed1b241f446acef"
dependencies = [
"anyhow",
"walrus 0.23.1",
"walrus",
"wasm-bindgen-wasm-conventions",
]
@ -15055,7 +15036,7 @@ dependencies = [
"anyhow",
"leb128",
"log",
"walrus 0.23.1",
"walrus",
"wasmparser 0.212.0",
]
@ -15067,19 +15048,10 @@ checksum = "170b4ec3be6a888c7fe3e221e18abc5981fc52e06215481e066a85fe25f0e6ad"
dependencies = [
"anyhow",
"log",
"walrus 0.23.1",
"walrus",
"wasm-bindgen-wasm-conventions",
]
[[package]]
name = "wasm-encoder"
version = "0.212.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501940df4418b8929eb6d52f1aade1fdd15a5b86c92453cb696e3c906bd3fc33"
dependencies = [
"leb128",
]
[[package]]
name = "wasm-encoder"
version = "0.214.0"

View file

@ -220,7 +220,7 @@ web-sys = { version = "0.3.56", default-features = false }
dirs = "5.0.1"
cargo-config2 = "0.1.26"
criterion = { version = "0.5" }
walrus = "0.22.0"
walrus = "0.23.1"
cargo_metadata = "0.18.1"
# desktop

View file

@ -10,7 +10,7 @@ description = "CLI Configuration for dioxus-cli"
keywords = ["dom", "ui", "gui", "react", ]
[dependencies]
wasm-bindgen = { workspace = true, optional = true }
# wasm-bindgen = { workspace = true, optional = true }
[features]
web = ["dep:wasm-bindgen"]
# web = ["dep:wasm-bindgen"]

View file

@ -17,21 +17,21 @@ pub const OUT_DIR: &str = "DIOXUS_OUT_DIR";
/// environment variables that the CLI sets, so we need to read them at compile time.
macro_rules! read_env_config {
($name:expr) => {{
#[cfg(debug_assertions)]
{
// In debug mode, read the environment variable set by the CLI at runtime
std::env::var($name).ok()
}
// #[cfg(debug_assertions)]
// {
// In debug mode, read the environment variable set by the CLI at runtime
std::env::var($name).ok()
// }
#[cfg(not(debug_assertions))]
{
// In release mode, read the environment variable set by the CLI at compile time
// This means the value will still be available when running the application
// standalone.
// We don't always read the environment variable at compile time to avoid rebuilding
// this crate when the environment variable changes.
option_env!($name).map(ToString::to_string)
}
// #[cfg(not(debug_assertions))]
// {
// // In release mode, read the environment variable set by the CLI at compile time
// // This means the value will still be available when running the application
// // standalone.
// // We don't always read the environment variable at compile time to avoid rebuilding
// // this crate when the environment variable changes.
// option_env!($name).map(ToString::to_string)
// }
}};
}
@ -87,51 +87,53 @@ pub fn is_cli_enabled() -> bool {
std::env::var(CLI_ENABLED_ENV).is_ok()
}
#[cfg(feature = "web")]
#[wasm_bindgen::prelude::wasm_bindgen(inline_js = r#"
export function getMetaContents(meta_name) {
const selector = document.querySelector(`meta[name="${meta_name}"]`);
if (!selector) {
return null;
}
return selector.content;
}
"#)]
extern "C" {
#[wasm_bindgen(js_name = getMetaContents)]
pub fn get_meta_contents(selector: &str) -> Option<String>;
}
// #[cfg(feature = "web")]
// #[wasm_bindgen::prelude::wasm_bindgen(inline_js = r#"
// export function getMetaContents(meta_name) {
// const selector = document.querySelector(`meta[name="${meta_name}"]`);
// if (!selector) {
// return null;
// }
// return selector.content;
// }
// "#)]
// extern "C" {
// #[wasm_bindgen(js_name = getMetaContents)]
// pub fn get_meta_contents(selector: &str) -> Option<String>;
// }
/// Get the path where the application will be served from. This is used by the router to format the URLs.
pub fn base_path() -> Option<String> {
// This may trigger when compiling to the server if you depend on another crate that pulls in
// the web feature. It might be better for the renderers to provide the current platform
// as a global context
#[cfg(all(feature = "web", target_arch = "wasm32"))]
{
return web_base_path();
}
// // This may trigger when compiling to the server if you depend on another crate that pulls in
// // the web feature. It might be better for the renderers to provide the current platform
// // as a global context
// #[cfg(all(feature = "web", target_arch = "wasm32"))]
// {
// return None;
// // return web_base_path();
// }
read_env_config!("DIOXUS_ASSET_ROOT")
}
/// Get the path where the application is served from in the browser.
#[cfg(feature = "web")]
// /// Get the path where the application is served from in the browser.
// #[cfg(feature = "web")]
pub fn web_base_path() -> Option<String> {
// In debug mode, we get the base path from the meta element which can be hot reloaded and changed without recompiling
#[cfg(debug_assertions)]
{
thread_local! {
static BASE_PATH: std::cell::OnceCell<Option<String>> = const { std::cell::OnceCell::new() };
}
BASE_PATH.with(|f| f.get_or_init(|| get_meta_contents(ASSET_ROOT_ENV)).clone())
}
// // In debug mode, we get the base path from the meta element which can be hot reloaded and changed without recompiling
// // #[cfg(debug_assertions)]
// // {
// thread_local! {
// static BASE_PATH: std::cell::OnceCell<Option<String>> = const { std::cell::OnceCell::new() };
// }
// BASE_PATH.with(|f| f.get_or_init(|| get_meta_contents(ASSET_ROOT_ENV)).clone())
// // }
// In release mode, we get the base path from the environment variable
#[cfg(not(debug_assertions))]
{
option_env!("DIOXUS_ASSET_ROOT").map(ToString::to_string)
}
// // // In release mode, we get the base path from the environment variable
// // #[cfg(not(debug_assertions))]
// // {
// // option_env!("DIOXUS_ASSET_ROOT").map(ToString::to_string)
// // }
None
}
pub fn format_base_path_meta_element(base_path: &str) -> String {

View file

@ -50,13 +50,15 @@ impl BuildRequest {
.await?;
}
let our_wasm_bindgen_version = wasm_bindgen_shared::version();
match self.krate.wasm_bindgen_version() {
Some(version) if version == wasm_bindgen_shared::SCHEMA_VERSION => {
Some(version) if version == our_wasm_bindgen_version => {
tracing::debug!("wasm-bindgen version {version} is compatible with dioxus-cli ✅");
},
Some(version) => {
tracing::warn!(
"wasm-bindgen version {version} is not compatible with the cli crate. Attempting to upgrade the target wasm-bindgen crate manually..."
"wasm-bindgen version {version} is not compatible with the cli crate ({}). Attempting to upgrade the target wasm-bindgen crate manually...",
our_wasm_bindgen_version
);
let output = Command::new("cargo")
@ -65,7 +67,7 @@ impl BuildRequest {
"-p",
"wasm-bindgen",
"--precise",
&wasm_bindgen_shared::version(),
&our_wasm_bindgen_version,
])
.stderr(Stdio::piped())
.stdout(Stdio::piped())

View file

@ -70,10 +70,10 @@ impl AppHandle {
// These need to be stable within a release version (ie 0.6.0)
let mut envs = vec![
(dioxus_cli_config::CLI_ENABLED_ENV, "true".to_string()),
(
dioxus_cli_config::APP_TITLE_ENV,
self.app.build.krate.config.web.app.title.clone(),
),
// (
// dioxus_cli_config::APP_TITLE_ENV,
// self.app.build.krate.config.web.app.title.clone(),
// ),
("RUST_BACKTRACE", "1".to_string()),
(
dioxus_cli_config::DEVSERVER_RAW_ADDR_ENV,
@ -81,12 +81,12 @@ impl AppHandle {
),
// unset the cargo dirs in the event we're running `dx` locally
// since the child process will inherit the env vars, we don't want to confuse the downstream process
("CARGO_MANIFEST_DIR", "".to_string()),
// ("CARGO_MANIFEST_DIR", "".to_string()),
];
if let Some(base_path) = &self.app.build.krate.config.web.app.base_path {
envs.push((dioxus_cli_config::ASSET_ROOT_ENV, base_path.clone()));
}
// if let Some(base_path) = &self.app.build.krate.config.web.app.base_path {
// envs.push((dioxus_cli_config::ASSET_ROOT_ENV, base_path.clone()));
// }
if let Some(addr) = fullstack_address {
envs.push((dioxus_cli_config::SERVER_IP_ENV, addr.ip().to_string()));

View file

@ -217,7 +217,7 @@ impl_serialize_const_tuple!(T1: 0, T2: 1, T3: 2, T4: 3, T5: 4, T6: 5, T7: 6, T8:
const MAX_STR_SIZE: usize = 256;
/// A string that is stored in a constant sized buffer that can be serialized and deserialized at compile time
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy, Hash)]
#[derive(PartialEq, PartialOrd, Clone, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConstStr {
#[cfg_attr(feature = "serde", serde(with = "serde_bytes"))]
@ -455,6 +455,12 @@ impl ConstStr {
}
}
impl std::fmt::Debug for ConstStr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.as_str())
}
}
#[test]
fn test_rsplit_once() {
let str = ConstStr::new("hello world");

View file

@ -26,8 +26,5 @@ rustversion = { workspace = true }
tokio = { workspace = true, features = ["full", "time"] }
trybuild = { workspace = true }
[features]
default = []
[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]

View file

@ -28,8 +28,8 @@ dioxus-liveview = { workspace = true, optional = true }
dioxus-ssr = { workspace = true, optional = true }
manganis = { workspace = true, features = ["dioxus"], optional = true }
serde = { version = "1.0.136", optional = true }
dioxus-cli-config = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
dioxus-cli-config = { workspace = true }
[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "android")))'.dependencies]
dioxus-devtools = { workspace = true, optional = true }
@ -54,7 +54,7 @@ router = ["dep:dioxus-router"]
fullstack = ["dep:dioxus-fullstack", "dioxus-config-macro/fullstack", "dep:serde"]
desktop = ["dep:dioxus-desktop", "dioxus-fullstack?/desktop", "dioxus-config-macro/desktop"]
mobile = ["dep:dioxus-mobile", "dioxus-fullstack?/mobile", "dioxus-config-macro/mobile"]
web = ["dep:dioxus-web", "dioxus-fullstack?/web", "dioxus-config-macro/web", "dioxus-cli-config", "dioxus-cli-config/web"]
web = ["dep:dioxus-web", "dioxus-fullstack?/web", "dioxus-config-macro/web"]
ssr = ["dep:dioxus-ssr", "dioxus-config-macro/ssr"]
liveview = ["dep:dioxus-liveview", "dioxus-config-macro/liveview"]
server = ["dioxus-fullstack?/axum", "dioxus-fullstack?/server", "ssr", "dioxus-liveview?/axum"]

View file

@ -18,9 +18,6 @@ proc-macro2-diagnostics = { workspace = true }
quote = { workspace = true }
syn = { workspace = true, features = ["full", "extra-traits", "visit", "visit-mut"] }
[features]
default = []
[dev-dependencies]
prettyplease = { workspace = true }
prettier-please = { workspace = true }

View file

@ -12,7 +12,7 @@ keywords = ["dom", "ui", "gui", "react", "wasm"]
[dependencies]
dioxus-core = { workspace = true }
dioxus-core-types = { workspace = true }
dioxus-cli-config = { workspace = true, features = ["web"] }
dioxus-cli-config = { workspace = true }
dioxus-html = { workspace = true }
dioxus-history = { workspace = true }
dioxus-document = { workspace = true }