Backtrace capture and printing add ~24 KB to wasm32-unknown-unknown builds that can never capture one
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start with src/backtrace.rs and src/fmt.rs, where the issue provides the proposed cfg changes. Check how backtrace! and the backtrace printing block are compiled for wasm32-unknown-unknown, then compare a wasm build with and without the change. Done means backtrace formatting code is omitted from that target while behavior remains unchanged.
Written by the indexing model from the issue text.
Description
On wasm32-unknown-unknown, std::backtrace::Backtrace::capture() never captures anything, but anyhow's Debug impl still references the backtrace printer, which pulls in std's backtrace formatting and rustc_demangle.
In a web page built with Dioxus's --wasm-split (which exports the whole function table, so nothing whose address is taken gets dropped), this measured about 24 KB of code before compression, 16 KB gzip, out of a ~130 KB gzip page (anyhow 1.0.104, Rust 1.93, Dioxus 0.7.10, opt-level = "z", LTO).
Gating the backtrace! macro to None, and the printing block in fmt.rs, on not(target_family = "wasm") removes it with no change in behaviour, since nothing could be captured there anyway. Would you take that, or a feature/cfg to opt out?
Related but opposite: #381 asks for a way to switch capture on in wasm.
--- a/src/backtrace.rs
+++ b/src/backtrace.rs
@@ -4,13 +4,20 @@
#[cfg(not(feature = "std"))]
pub(crate) enum Backtrace {}
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", not(target_family = "wasm")))]
macro_rules! backtrace {
() => {
Some(std::backtrace::Backtrace::capture())
};
}
+#[cfg(all(feature = "std", target_family = "wasm"))]
+macro_rules! backtrace {
+ () => {
+ None
+ };
+}
+
#[cfg(not(feature = "std"))]
macro_rules! backtrace {
() => {
--- a/src/fmt.rs
+++ b/src/fmt.rs
@@ -40,7 +40,7 @@
}
}
- #[cfg(feature = "std")]
+ #[cfg(all(feature = "std", not(target_family = "wasm")))]
{
use alloc::string::ToString;
use std::backtrace::BacktraceStatus;
- Dominant language
- Rust
- Stars
- 6.7k
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dtolnay/anyhow
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Construct Error with existing backtracePossibly taken @sb123sb123 claimed this 55 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
`ensure!` doesn't accept inline const blocksPossibly taken @FadeHack claimed this 85 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 48/100
Similar issues
-
Selected chart highlights only its values, not its series names and category labelsPossibly taken @Higgs32584 claimed this today. Openbug priority: low ui
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
storytold/gridcraft#4390 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
bug bugfix priority: medium
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
quarto-dev/q2#1219 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
BurntSushi/jiff#713 ·
Maintainers usually reply within 1 day