tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
813 stars 224 forks source link

Reduce binary size on some plugins #1085

Open Legend-Master opened 5 months ago

Legend-Master commented 5 months ago

I think binary size is important for tauri plugins, as this is the biggest advantage for Tauri vs Electron

Did some testing on plugin size compiling examples/api, I commented out all extensions, and add in one at a time, here's the increased size of some plugins

Base size 3.34 MB (On Windows)

Plugin Size Increase
shell 4.72 MB 1.38 MB
updater 4.25 MB 0.91 MB
fs 3.61 MB 0.27 MB
dialog 3.47 MB 0.13 MB
log 3.46 MB 0.12 MB
store 3.45 MB 0.11 MB
Legend-Master commented 5 months ago

Shell plugin is bloated because of regex I think (this reminds me that Lua doesn't have standard regex, because regex itself is bigger than the entire Lua interpreter + libraries (~500 KB))

1.47 MB for (empty main is 130 KB)

fn main() {
    use regex::Regex;

    let re = Regex::new(r"\b\w{13}\b").unwrap();
    let hay = "I categorically deny having triskaidekaphobia.";
    assert!(re.is_match(hay));
}

We're currently using regex to control open scope permissions, maybe we can put it in to a feature?

Removing regex reduced the size to total of 3.68 MB, 0.34 MB increase from base line compare to 1.38 MB

amrbashir commented 5 months ago

I only see shell plugin as an issue, other plugins size are fine IMO and not sure if they can be trimmed even further.

amrbashir commented 5 months ago

Regex was used in v1 but was behind a feature flag based on the allowlist config but now that we moved to ACL in v2, it is no longer feature flagged and is always included in the final binary, I guess we need to figure out a way to bring a similar behavior back. cc @lucasfernog

Legend-Master commented 5 months ago

updater plugin's size can be reduced by moving updater out of zip/tar, and remove them as dependencies (#1083), other plugins are fine though

cli plugin uses clap, which is also quite big (~0.7MB), but it's not that important since you can use something else like argh without the plugin anyway

Also, about the regex, can we switch to something like the one we used for the fs plugin, and put regex one behind a feature? I think most of the time we just need to control the path, and regex is pretty hard to use on paths anyway

lucasfernog commented 5 months ago

shell uses regexes to validate arguments (both to commands and the open() API). removing this support only lets you use fixed arguments, so I think we should move regex to a feature flag but enable it by default.