Skip to content

feat: reduce Debug format size for binary buffers - #13809

Merged
lucasfernog merged 6 commits into
devfrom
feat/custom-debug-for-binary-blobs
Jul 25, 2025
Merged

feat: reduce Debug format size for binary buffers#13809
lucasfernog merged 6 commits into
devfrom
feat/custom-debug-for-binary-blobs

Conversation

@Beanow

@Beanow Beanow commented Jul 11, 2025

Copy link
Copy Markdown
Member

This makes the debug output of large Tauri structs more manageable.
I primarily looked at AppHandle and the binary buffer fields that it contains.

Try it out by logging the AppHandle in examples/api/src-tauri/src/lib.rs:

log::info!("Running app {app_handle:?}");

The icons, images and (compressed) assets can cause some massive debug outputs because their contents are arbitrarily large and the formatting of bytes as decimals ([0, 0, 0, 0, ...]) is not compact either.

Generally I'm formatting them here as [u8; {len}] similar to the type definition for a fixed length array.

Alternatives

I used some temporary structs which are only used during the formatting itself. Instead we could also create permanent structs to override the Debug behavior.

Benefit would be that in some cases we can go back to deriving Debug for the parent struct. Downside is we'd need to implement more than just Debug to retain all the properties we care about, like Clone and accessing the contents.

As alternative format to the [u8; {len}] we could also use a more compact notation that preserves the contents like base64. Benefit would be you can still debug the contents of these buffers. Downside is it would still be arbitrarily large, just more dense.

@github-actions

github-actions Bot commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Package Changes Through 5093c65

There are 6 changes which include @tauri-apps/cli with patch, tauri-cli with patch, @tauri-apps/api with patch, tauri-bundler with patch, tauri with patch, tauri-utils with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.6.0 2.6.1
tauri-utils 2.5.0 2.5.1
tauri-bundler 2.5.0 2.5.1
tauri-runtime 2.7.0 2.7.1
tauri-runtime-wry 2.7.1 2.7.2
tauri-codegen 2.3.0 2.3.1
tauri-macros 2.3.1 2.3.2
tauri-plugin 2.3.0 2.3.1
tauri-build 2.3.0 2.3.1
tauri 2.6.2 2.6.3
@tauri-apps/cli 2.6.2 2.6.3
tauri-cli 2.6.2 2.6.3

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

Beanow added 4 commits July 11, 2025 15:41
For example now:
`Image { rgba: Cow::Borrowed([u8; 4096]), width: 32, height: 32 }) }`
For example now:
```
EmbeddedAssets {
    assets: {
        "/index.html": [u8; 1835],
        "/index.js": [u8; 212],
    },
    global_hashes: [
        Script(
            "'sha256-EOd6N98xxmK5s7VvxV7W2w7YG+dmP52MqNiZUq1NLeE='",
        ),
        Style(
            "'sha256-YEercZJImS+vUX2bz7vkQ0aA4rtBIPLuCEWz+yraQ/g='",
        ),
    ],
    html_hashes: {
        "/index.html": [
            Script(
                "'sha256-3g8CfFrjFLGpwD2o+hwMt+lh/hsHbQ3XY+EPJ35fFKk='",
            ),
            Script(
                "'sha256-EOd6N98xxmK5s7VvxV7W2w7YG+dmP52MqNiZUq1NLeE='",
            ),
        ],
    },
}
```
@Beanow
Beanow force-pushed the feat/custom-debug-for-binary-blobs branch from 9f09e96 to 0ecd36e Compare July 11, 2025 13:44
Comment thread crates/tauri/src/lib.rs
Comment on lines 423 to 428
d.field("config", &self.config)
.field("default_window_icon", &self.default_window_icon)
.field("app_icon", &self.app_icon)
.field("app_icon", &DebugAppIcon(&self.app_icon))
.field("package_info", &self.package_info)
.field("pattern", &self.pattern)
.field("plugin_global_api_scripts", &self.plugin_global_api_scripts);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: these are missing several fields that exist on the struct.
I'm not sure whether that's intentional or whether the Debug implementation just is out of date.

Comment on lines 233 to 238
.field("plugins", &self.plugins)
.field("state", &self.state)
.field("config", &self.config)
.field("app_icon", &self.app_icon)
.field("app_icon", &DebugAppIcon(&self.app_icon))
.field("package_info", &self.package_info)
.field("pattern", &self.pattern);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise missing fields.

@Beanow
Beanow marked this pull request as ready for review July 11, 2025 13:50
@Beanow
Beanow requested a review from a team as a code owner July 11, 2025 13:50
Comment thread crates/tauri/src/lib.rs
/// data as a slice of numbers `[65, 66, 67]`. This instead shows the length of the Vec.
///
/// For example: `Some([u8; 493])`
pub(crate) struct DebugAppIcon<'a>(&'a Option<Vec<u8>>);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't 100% sure on this one. Because it seems only macos uses this app_icon.
On Linux it was always None for me.

@lucasfernog
lucasfernog merged commit 72b4226 into dev Jul 25, 2025
3 checks passed
@lucasfernog
lucasfernog deleted the feat/custom-debug-for-binary-blobs branch July 25, 2025 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants