Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.

types: add compact-errors feature - #1064

Open
benma-agent wants to merge 1 commit into
rust-bitcoin:masterfrom
benma-agent:benma-agent/compact-errors
Open

benma-agent wants to merge 1 commit into
rust-bitcoin:masterfrom
benma-agent:benma-agent/compact-errors

Conversation

@benma-agent

Copy link
Copy Markdown

Let size-sensitive applications omit fragment strings from type-checking
errors so otherwise unused fragment-formatting code can be removed from
the binary.

Add an opt-in compact-errors feature that leaves Error::fragment_string
empty while preserving ErrorKind and all parsing and validation behavior.
Reuse the existing error wrapper for threshold errors so both paths follow
the same feature setting. Display still includes the error reason with an
empty fragment; detailed diagnostics remain the default.

Assisted-by: OpenAI Codex (GPT-6)

Let size-sensitive applications omit fragment strings from type-checking
errors so otherwise unused fragment-formatting code can be removed from
the binary.

Add an opt-in compact-errors feature that leaves Error::fragment_string
empty while preserving ErrorKind and all parsing and validation behavior.
Reuse the existing error wrapper for threshold errors so both paths follow
the same feature setting. Display still includes the error reason with an
empty fragment; detailed diagnostics remain the default.

Assisted-by: OpenAI Codex (GPT-6)
@benma

benma commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

We use this dep in the BitBox02 firmware and would appreciate this (or something similar) being included, as it would significantly reduce binary size.

@apoelstra

Copy link
Copy Markdown
Member

Yeah, I think this is fine. Does it really reduce your binary size though? It just removes a runtime descriptor serialization.

@benma

benma commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Yeah, I think this is fine. Does it really reduce your binary size though? It just removes a runtime descriptor serialization.

Yes, it reduces the binary size by about 6.3kb (Rust 1.96.0, opt-level = "z" and LTO).

From the agent:

The runtime fragment.to_string() call keeps the fragment serialization implementation reachable in the binary. Replacing it with String::new() lets the optimizer/linker discard the formatting and tree-traversal code that becomes unused.

I also checked the linked symbols: the DisplayNode traversal helpers and Terminal::fragment_name instantiations for both String and bitcoin::PublicKey are present with the feature disabled and disappear with it enabled.

@apoelstra

Copy link
Copy Markdown
Member

Yeah, my guess was that this was eliminating the only callsite to Descriptor::fmt.

So, this seems pretty fragile. Like, if anybody formats a descriptor anywhere in your codebase then the formatting code would be reintroduced and the feature gate would be negated.

A better approach might be to directly feature-gate the formatting logic. But then, I wonder if the formatting logic is the best target. It seems like there are lots of "big algorithms" in this codebase and different users might like to avoid different subsets of them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants