Reduce build times #33
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially addresses #19.
I've got some good news and I've got some bad news. 🥲
While experimenting, I was running variations of this command to get the clean build timing:
Let me know if that's the wrong command. Hopefully the changes help. 🤞
Good News
I was able to reduce the build time of
inputmodule-control
by half on my machine (60 seconds -> 27 seconds). Using the--timings
flag during the build, I tracked down a big chunk of time to theimage
crate. I disabled all default features and enabled onlybmp
,png
, andgif
since that's what I see looking around the repo.clap
is the other big one, but the default features seemed necessary for what the SW tool is doing.You can likely further reduce your build times if you set up
sccache
locally. You can install it withcargo install sccache
. Then, when you go to build, you just need to add theRUSTC_WRAPPER
envvar. For example:I briefly looked at setting up
sccache
in github actions, but didn't find any great examples (and also saw mixed feelings about using it).Bad News
Further build time reduction is possible, but requires a larger effort. For example, you can get a much lower time with:
That modification in combination with a local
sccache
, I got the build down to about 4 seconds on a 3950x (6 if you don't usesccache
).The reason I think it will take a larger effort for further reduction is because the crate will likely need to be reworked into either two separate repos or two separate cargo workspaces. I can file this as a new issue if desired.
There are a couple of factors:
cargo build
for either a mcu or the host app, both will use the same definitions (and build.rs script). That means a lot of unnecessary optimizations are happening in the much larger (comparatively) host app. Embedded Rust does a lot of weird non-standard (necessary) things that end up playing havoc with "regular" applications.per-package-target
is meant to be used the way the workspace is setting up for it. After reading through the docs, it looks likeper-package-target
is more intended for having a single package distributed across different architectures. It looks more like a way to control features per target environment for a single app rather than a way to build packages that have different functionalities.It's likely the issue will pop up again if you want to start adding feature flags or other more advanced workspace management stuff.
Personally, I like the two repo approach (CLI utility + Firmware). I've used it in the past and I've found it generally easier to manage the projects that way. But I also understand wanting to keep everything in a monorepo. Either way, I do think two workspaces are needed.
Bonus News
As a side effect, the change should reduce your GHA build times by half. At least it did in my fork. 🤷♂️