markup.rs icon indicating copy to clipboard operation
markup.rs copied to clipboard

Add optional caching

Open pzmarzly opened this issue 6 years ago • 4 comments

In a project I'm working on, this decreases overall build time from between 8 and 10 to between 5 and 7 seconds.

pzmarzly avatar Sep 14 '19 11:09 pzmarzly

Faster build time (considering my own is 10+ mins) is always good.

:+1:

ZaneHannanAU avatar Sep 14 '19 11:09 ZaneHannanAU

While a faster build time is good, I'm not sure about writing cached files into the user's system's cache directory. Is there any other popular crate which does this?

utkarshkukreti avatar Sep 17 '19 09:09 utkarshkukreti

Is there any other popular crate which does this?

I wasn't familiar with any, which is why I suggested it as an optional feature. Quick search on crates.io led me to gmp-mpfr-sys, which creates temporary files in ~/.cache/gmp-mpfr-sys, though it doesn't have to (it could use $OUT_DIR provided by cargo).

I was thinking about using target dir, but AFAIK we don't get any path to it. We would need to either:

a) assume it's $PWD/target - but it's sometimes not, b) assume it's $CARGO_MANIFEST_DIR/target - false in multi-crate projects, c) use $PWD to find a topmost directory that contains both Cargo.toml and target - which would work for 99% of use cases, but that 1% of users could get surprised

Many Rust developers already have large ~/.cargo/registry and ~/.cache/sccache dirs, so I thought writing few hundred KBs to ~/.cache wouldn't be that much of an issue if users were warned about that.

pzmarzly avatar Sep 17 '19 10:09 pzmarzly

Cargo actually provides a per-crate temporary directory for such a use-case. You can have a look how I use caching in Nate: build.rs, generate.rs. (Actually I use it because then you have better error messages. The caching is only a by-product.)

Kijewski avatar May 24 '22 16:05 Kijewski