Optimise compile times and binary sizes #9
Labels
No Label
bug
documentation
duplicate
enhancement
help wanted
invalid
maintenance
peach-lib
peach-network
peach-oled
peach-stats
peach-web
question
refactor
wontfix
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: PeachCloud/peach-workspace#9
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Sharing a few resources here to inform further exploration and discussion.
This is definitely not a major priority, but I would like to refactor everything at some point to reduce compile times and binary sizes (and generally improve the handling and reporting capabilities of PeachCloud).
Rust: Structuring and handling errors in 2020
Response to above article by burntsushi
thiserror crate
anyhow crate
Re-evaluate error handling and reportto Re-evaluate error handling and reportingI experimented with refactoring peach-stats today. By replacing
serde
withminiserde
, removingsnafu
and replacing it with custom error implementations, I was able to achieve the following:43% reduction in dependencies
20% reduction in compile time
16% reduction in binary size
Total number of dependencies dropped from 224 to 128.
Release build compilation time dropped from 27.31s to 21.97s.
Release build binary size dropped from 8402184 to 7047600 bytes.
After running
strip
on the post-refactor binary, size dropped to 2716368. That represents a 67% reduction in binary size; from 8 MB to 2.6 MB. If we really want to squeeze the size, we can also tell the compiler to abort on panic (rather than unwinding the stack). This gets us down to 2 MB.I also upgraded direct dependencies to their latest versions.
The actual code refactoring did not take very long. I think this set of changes could be applied across our codebase with great effect.
Re-evaluate error handling and reportingto Optimise compile times and binary sizes@glyph cool that you got inspired by this rabbit hole, and thanks for sharing the results in this very scientific way!
these seem like really solid gains, and I just looked through the PR, and the interface for working with it as a developer feels just as easy to work with as before
so this seems like a good switch to me too
I'd be curious to understand more what are the features that snafu tries to give you over the standard error implementation, but just out of curiosity
in general I think we should also value "developer efficiency" (ease of working with, understanding and making changes to the code) for the patterns we use, in addition to "compile time and binary size efficiency", but this feels like a win in both categories
@notplants
Thanks for taking a look. I agree on aiming for a balance of developer efficiency and code optimisation. One of the intentions of the PeachCloud codebase is to be an idiomatic, best-practice resource for learning Rust. I'm starting to see that reaching for the easiest-to-use crate is not always best practice; sometimes it's better to take the handwritten route (and you generally learn more in the process).
I must admit, I'm still learning all the facets of what makes a "good" error implementation. I think my code in #11 is probably missing a few nice-to-have features.
Snafu have some good docs to learn more about this:
SNAFU's design philosophy
Details about the output of the Snafu macro
This weekend I discovered upx: "a free, portable, extendable, high-performance executable packer for several executable formats".
upx adds decompression logic to the binary itself, meaning that the compressed binary can be executed as normal - without having to first decompress it.
I'm seeing 30-40% reduction in binary size. This could be a huge win for us!
The path, as I currently see it:
strip
the release build binaryupx
Another great resource:
Tips for Faster Rust Compile Times by Matthias Endler
I intend on refactoring peach-web to use maud and rouille, now that I know for certain that we'll still be able to invoke async golgi functions.