Skip to content
Browse files
Cargo bloat time (#89)
Add cargo bloat post
  • Loading branch information
orf committed Apr 27, 2020
1 parent 6951635 commit 5e5a7230dcf82a7d8bfdeb401c46c16575889016
Showing 11 changed files with 382 additions and 354 deletions.
@@ -28,6 +28,10 @@ url = ""
posts = ":slug/"


anonymizeIP = true
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,48 @@
title: "Managing Rust bloat with Github Actions"
date: 2020-04-23T22:42:54+01:00
- projects

Cargo and []( are an amazing part of the Rust ecosystem and one of the things that makes
Rust so pleasant to work with. However, it's quite easy for your cargo dependencies to pile up without you noticing.
For example you might blindly add the (rather awesome) [reqwest]( crate, not
realizing that it [might increase your binary size by over 4mb](

Now, you might be thinking to yourself, "does it really matter?", and the answer might well be "no". However, I think
it's important to have _some idea_ about your binary sizes and number of dependencies in your project as you make changes.
It might not be worth adding a specific library, and it's associated size overhead, when a smaller and simpler library might suffice.

### Introducing Cargo Bloat Action

View it on Github:

Cargo Bloat Action is a Github Action that gives you insights into how code and dependency changes change both your
dependency tree and your final binary size.

{{< image-box name=comment.png >}}
An example pull request comment
{{< /image-box >}}

### How it works

Under the hood the action uses two tools: [cargo-bloat]( and
[cargo-tree]( These are orchestrated by
[a TypeScript file](

#### Master builds

When a build is running on the master branch, any results are sent to a
[small lambda]( running on Google Cloud.

#### Pull Requests

When a pull request is made, the results from the last pull request are fetched from the lambda and used to generate
lovely diffs, which are then displayed as comments in the merge request.

#### Suggestions for improving Github Actions

Creating a lambda for this kind of sucks, and it's not super secure. I would think that recording and fetching some
kind of metric (like code coverage, or binary size) is a pretty common occurrence - it would be fantastic if Github
actions supported this out of the box. Maybe the ability to securely store and fetch up to 10kb of JSON per repository?
@@ -73,11 +73,10 @@ versus the simplicity of other databases. Here is how you get the query executio
2. You also have no real way of knowing if this function is available or can be called without error

So this is a pretty complex workflow to just get a query plan, but it's doable. I had this feature working in my
branch and it seemed OK. Until I hit a blocker.
branch and it seemed OK. Until I hit a blocker:

<center><strong>You cannot explain parameterized queries</strong></center>

<div class="has-text-centered"><strong>You cannot explain parameterized queries!</strong></div>

Yeah. So... that's a blocker. All queries in Django are parameterized to prevent SQL injections, so rather than executing
@@ -93,4 +92,4 @@ SELECT * FROM table WHERE id = ?;
and pass `1` as the parameter (denoted as `?` in the query above). With oracle you cannot do this, all parameters must
be filled in.

So that's why we cannot support Oracle with this, which kind of sucks.
So that's why we cannot support Oracle with this, which kind of sucks.
Deleted file not rendered
@@ -30,7 +30,10 @@ the way it had to fetch the entire catalogue of icons when I was just using four
system they are pushing but I found that it absolutely destroyed the page load metrics I was looking at in Chrome. It
also ended up making a lot of requests:

{{< image-box name=screenshot.png >}}
{{< /image-box >}}

### Stripping unused css

@@ -74,4 +77,4 @@ And including this `package.json` file:
"purgecss": "^1.4.0"
@@ -0,0 +1,24 @@
<div class="columns is-centered">
<div class="column is-three-quarters-desktop">
<div class="card">
<div class="card-image">
<figure class="image" style="margin: 0">
{{ $img := .Page.Resources.GetMatch (.Get "name") }}
{{ with (.Get "fit") }}
{{ $scaled := $img.Fit . }}
<img src='{{ $scaled.Permalink | safeURL }}'/>
{{ else }}
<img src='{{ $img.Permalink | safeURL }}'/>
{{ with .Inner}}
<div class="card-content" style="padding-top: 0; padding-bottom: 15px">
<div class="content has-text-centered is-size-7-mobile">
{{ . | safeHTML}}
{{ end}}
@@ -1,6 +1,6 @@
environment = { HUGO_VERSION = "0.69.0" }
command = "git submodule update --init --recursive --depth=1 && hugo --minify"
command = "git submodule update --init --recursive --depth=1 && hugo --minify --ignoreCache"

command = "git submodule update --init --recursive --depth=1 && hugo -b $DEPLOY_PRIME_URL --minify"
command = "git submodule update --init --recursive --depth=1 && hugo -b $DEPLOY_PRIME_URL --minify --ignoreCache"

0 comments on commit 5e5a723

Please sign in to comment.