the-lean-crate / criner

A tool to mine crates.io and produce static websites
MIT License
122 stars 2 forks source link

Rust crates.io version

The Lean Crate Initiative

We want to improve build times by reducing download and extraction times. This makes the ecosystem more approachable to people or regions with slow internet and thus is very relevant for inclusiveness and for extending Rusts reach.

This is facilitated by three means:

Motivation

I lived in China and learned to live with slow and flaky internet connections. Every byte that reaches my computer makes me shed a tear in joy.

This initiative was motivated by a nushell update which took forever and failed multiple times when trying to send me 3MB of images in a 4MB download. The fix was trivial, and I wondered how much more there was to gain by simple fixes like that. The idea for The Criner Waste Report was born, which soon turned into a multi-step plan to tackle this problem.

Nowadays, nushell is perfectly lean, and I hope we will have more of these crates as the initiative progresses.

How you can help right now

First of all, thanks so much for your willingness to help! Let's get started.

Head over to The Criner Waste Report and find your crate or jump to your crate directly using https://the-lean-crate.github.io/waste/<your-crate>. See if a lot of 'waste' is detected, and validate and try the suggested fix. If something is wrong or not working, click the Provide Feedback link at the bottom of your crates page.

Example: There is some 'Waste' to be removed

Example: The crate is lean - there is nothing to do, or is there?

The Criner Waste Report

As the first part of The Lean Crate Initiative, this report provides the data needed to see if this is a problem worth solving in the first place. And as of 2020-03-18, initial numbers show that out of 147GB of uncompressed crates data, 59GB or 40% are most probably not required to build a crate.

The report operates on the following assumptions:

From these assumptions, some conclusions can be drawn. There is no need for…

Based on these assumptions and conclusions, The Criner Waste Report computes a suggestions for new include or exclude directives which prevent unnecessary data to be put into the crate archive.

Due to the way Cargo handles these directives, include directives are deemed most powerful in the persuit of keeping the amount of patterns small, using negative patterns where needed. Thus these will be recommended whenever feasible.

This part of the initiative is still under heavy development, but available as ugly alpha.

Please do note that your feedback on whether or not these assumptions and conclusions are correct is much appreciated, everything can be changed to make The Criner Waste Report better in a collaborative, community driven effort.

The cargo diet Companion Program

The logic employed in 'The Criner Waste Report' is available at your finger tips using cargo diet, making it easy to start out with a perfectly lean crate even when publishing a crate for the first time.

asciicast

FAQ

How dare you call anything in my crate 'Waste' ??!

Apologies, the term was proposed by the marketing department who believed that 'The Criner Waste Report' will do better than 'The Criner Report of files you do not need to build a crate'.

The author does shame crates that are bigger than they probably have to be, and is happy to help get your crate off the index. Some files listed are certainly false positivies due to limitations, read on in this FAQ to learn how to remove these false positives.

It claims my crate is full of waste because it doesn't see what the build-script requires ?!

Indeed the Waste Report does its best to extract names from build scripts, but won't be able to resolve things like format!("C-lib-1.0.23-{}", suffix). To resolve this, set your own include directive. The Criner Waste Report will help finding even better includes from that point on, but it will merely be a suggestion, trusting that you set includes exactly the way they are needed.

It keeps claiming that my included files are waste !?

It detecs files included via include_str!(…) and include_bytes!(…), but only so in in lib.rs and main.rs, or other binary targets.

How can I just make it stop complaining ?

Add the include = […] that it proposes, possibly altered to your liking and needs. It will still provide you with potential negated include patterns to exclude, for instance, tests and docs.

What's better, exclude directives or include directives?

The waste report favors include directives, as it will not mark any file as wasted if present, but make recommendations on how to save even more by excluding tests, docs and the likes.

When excludes are present, it makes recommendations mandatory, and considers all files that don't are included despites those recommendations to be waste. The reason is that whitelists, i.e. include directives, are better supported by cargo due to the presence of negations, so it assumes people have better control over the includes they make.

What are "potential savings"?

It's our way to hint at the possibility of making your crate smaller while acknowledging that your include directive is probably exactly what you had in mind when designing it.

However, right now we believe that certain kinds of files are not needed to build a crate and thus may have additional negation patterns that would exclude these files. Common examples are tests, which are easily included by the typical src/**/*.rs include directive.

Potential savings do not count as 'Waste', but currently prevent the crate version from achieving the perfectly lean status.

Limitations of Waste Reporting

Fun facts

Criner

Criner is a platform to make incrementally mining crates.io easy and affordable for everyone. Criner is fast, configurable to use all available bandwidth and CPU, while keeping the memory footprint low enough to comfortably run on small devices with less than 512MB of RAM.

How it works

Criner currently operates in three stages when executed with criner mine:

Running Criner at home

Clone this repository and run cargo run --release -- mine to get started. Provided criner is allowed to finish, it will require about 46GB of disk space as of 2020-03-18.

Criner for data science

Provided there is a database generated already with criner mine, run criner export to get another SQlite database with all data exploded into tables and fields, which can be operated using SQL. This process is non-incremental and takes about 5 minutes to complete on a single core. Threading is not implemented.

Some of the columns are of type JSON, whose properties can be used in queries using the json_*(…) set of SQLITE functions.

Possible improvements are along export performance - it could probably be parallel and incremental - and along not having to mine yourself for an initial database state. Criner could upload its database once a day to an S3 bucket for instance - it's about 800MB gzipped.

Operating Manual

How to run migrations

As migrations are currently special purpose programs that may eat laundry for breakfast, they cannot be executed by accident.

RUST_LOG=info cargo run --features migration  --  migrate