dioxus-web: AttributeValue::Float uses f64::to_string, pulling ~13 KB of float printing into every web build

Open Beginner friendly
#6,089 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, wasm

Research direction

Start in packages/web/src/mutations.rs at the AttributeValue::Float arm and check how the web crate handles JavaScript number conversion and its dependencies. Compare the generated release Wasm size with the current formatting path and the proposed browser formatting path; done means the float attribute uses browser formatting and the build no longer includes float printing solely for this conversion.

Written by the indexing model from the issue text.

Description

packages/web/src/mutations.rs sets float attributes with &f.to_string(), which links core::fmt::float / flt2dec (about 13 KB raw, 8 KB gzip) into every web build, even an app that never sets a decimal attribute (measured with dioxus-web 0.7.10, dx build --release --wasm-split, opt-level = "z", LTO).

Letting the browser format the number avoids it:

             AttributeValue::Float(f) => self.interpreter.set_attribute(
                 id.0 as u32,
                 name,
-                &f.to_string(),
+                &String::from(js_sys::Number::from(*f).to_string(10).unwrap_or_default()),
                 ns.unwrap_or_default(),
             ),

The only visible difference is the browser's spelling for extremes (1e+21 and Infinity instead of 1000000000000000000000 and inf), which is what the DOM would show for those values anyway. Happy to open a PR if that's welcome.

Dominant language
Rust
Stars
39.8k
Forks
2k
Avg merge
14h 29m
Merged PRs (30d)
20

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DioxusLabs/dioxus

All issues in DioxusLabs/dioxus

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.