feat: reduce Debug format size for binary buffers#13809
Conversation
Package Changes Through 5093c65There 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 VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
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='",
),
],
},
}
```
9f09e96 to
0ecd36e
Compare
| 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); |
There was a problem hiding this comment.
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.
| .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); |
| /// 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>>); |
There was a problem hiding this comment.
Wasn't 100% sure on this one. Because it seems only macos uses this app_icon.
On Linux it was always None for me.
This makes the debug output of large Tauri structs more manageable.
I primarily looked at
AppHandleand the binary buffer fields that it contains.Try it out by logging the AppHandle in
examples/api/src-tauri/src/lib.rs: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.