New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace AttributeValue::Text
with Cow<'static, str>
#2308
base: main
Are you sure you want to change the base?
Conversation
Does this mean I won't be able to do this
Hated having to
|
Unfortunately this would be a breaking change but I'd say the optional solution is Then you can still do |
I would be interested to see benchmarks if this has a large performance impact. Dioxus will currently not allocate with static strings inline in the rsx: rsx! {
div {
// "hello world" is included in the template which only supports &'static str attributes
width: "hello world",
}
} This PR would enable less allocation for the following code: const STATIC: &str = "hello world";
const STATICS: &[&str] = &["hello world"];
let index = use_signal(|| 0);
rsx! {
div {
// Theoretically this could be part of the template as well, but we are currently not smart enough to know that it is static
width: STATIC,
// This shouldn't be part of the template because it is dynamic
height: STATICS[index()],
}
} There is also some overlap with https://github.com/DioxusLabs/dioxus/pull/2258/files#diff-b96a80b4b2e2f0da84fe76143d9f213d159383fd322e41068eba85fcd7fe93f3 which introduces string type with static and dynamic segments (currently only used in debug mode for hot reloading) |
TODO: Greg Johnston's new oco_ref crate might fit great here 馃憖 |
This would allow for less clones when using text nodes.
However this does introduce the tradeoff of not automatically converting
&str
toString
, only&'static str
is permitted to reduce cloning.Definitely open to changing any of this! 馃槃