DiscordTauri/discord-tauri

Additional optimisations for the binary

snowc0de opened this issue · 16 comments

I did a few more optimisations on the binary size by adding the following to the Cargo.toml file :

[profile.release]
strip = true
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"

Then I ran this to reduce the binary even more :

upx --best --lzma src-tauri/target/release/tauricord

All of this left me with a final binary that is just 656K.

(the optimisations come from here)

PS: It is worth noting that upx might make the initial load time of the app a bit slower because I think it has to decompress the binary in the RAM. Also I just noticed that this project is a bit more complex than I thought, so my project actually doesn't have all the things in the main.rs file and I'm on Linux too.

@chopin2712 how can I use this repo on linux can you help?

Hey @toprak, install Tauri following the instructions in https://tauri.app

Then clone the repo and run "npm install", "npm run tauri release"

After building, the binary will be in src-tauri/target/release

As for the size optimizations, feel free to make a pull request! I'm building a new PC right now but I can merge from mobile.

Also, I don't think using UPX is the perfect solution. But if it brings an astonishingly good compression ratio, you can put it in the scripts to run after building (maybe create a build.sh/build.bat?)

@toprak

Hello. I just built it from Linux and It compiled just fine (I just had to install libappindicator-gtk3). What exactly is the problem with this project on Linux?

If you never used cargo or tauri on Linux before you can run the following commands:

# This command to install cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# This command to install tauri
cargo install tauri-cli

# This command to download this project
git clone https://github.com/DiscordTauri/discord-tauri
cd discord-tauri

# Then this command to run (in dev mode) the project
cargo tauri dev

The commands provided by @RealDrPuc should also work, but I prefer using Cargo because I don't like nodeJS, yarn, npm and that kind of stuff.

@RealDrPuc For the pull request I can, but I'm not sure if it's a good idea to make scripts like this. Since there are a lot of different ways to install it (yarn, cargo, etc), and we would also have to manage all the different platforms and stuff.

I would rather just add it to the README or start a wiki on this project.

Yeah, that's a good point. I like the wiki idea, si you wanna work on it?

@chopin2712 @RealDrPuc I could not find a fix to this
error: failed to write /tmp/cargo-installCOd0TP/release/.fingerprint/proc-macro2-d0f47c358fb477a1/invoked.timestamp`

Caused by:
No space left on device (os error 28)
error: failed to write /tmp/cargo-installCOd0TP/release/.fingerprint/unicode-ident-38ae3080f8175d05/invoked.timestamp

Caused by:
No space left on device (os error 28)
error: failed to write /tmp/cargo-installCOd0TP/release/.fingerprint/syn-24db8b936867bdce/invoked.timestamp
`

@toprak How much space is left on your device ? Can you send a copy of

df -h

?

Your disk is full!

Nevermind, /tmp is on tmpfs

@chopin2712 here

Filesystem      Size  Used Avail Use% Mounted on
dev             1.4G     0  1.4G   0% /dev
run             1.4G  944K  1.4G   1% /run
/dev/sda1       442G   72G  348G  18% /
tmpfs           1.4G   68M  1.4G   5% /dev/shm
tmpfs           1.4G  1.4G     0 100% /tmp
tmpfs           285M   32K  285M   1% /run/user/1000

I like the wiki idea, si you wanna work on it?

@RealDrPuc I can try, but I might not work a lot on it since I'm also a student and I'm currently in an exam period.

Filesystem Size Used Avail Use% Mounted on dev 1.4G 0 1.4G 0% /dev run 1.4G 944K 1.4G 1% /run /dev/sda1 442G 72G 348G 18% / tmpfs 1.4G 68M 1.4G 5% /dev/shm tmpfs 1.4G 1.4G 0 100% /tmp tmpfs 285M 32K 285M 1% /run/user/1000

It is very hard to read this, it would be a bit easier if you would use code blocks.

I like the wiki idea, si you wanna work on it?

@RealDrPuc I can try, but I might not work a lot on it since I'm also a student and I'm currently in an exam period.

Yeah that's fine, study is first! I'm also a student and had to leave this project a bit 🥲

@toprak OK I figured out what your output meant

Filesystem      Size  Used Avail Use% Mounted on
dev             1.4G     0  1.4G   0% /dev
run             1.4G  944K  1.4G   1% /run
/dev/sda1       442G   72G  348G  18% /
tmpfs           1.4G   68M  1.4G   5% /dev/shm
tmpfs           1.4G  1.4G     0 100% /tmp
tmpfs           285M   32K  285M   1% /run/user/1000

You don't have any space left in /tmp

@RealDrPuc Waiting for when I'll have the time to really work on this, could you enable the wiki? I think only maintainers can do that

@RealDrPuc I just added the installation instructions for Linux here