Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust-Script caching does not work #968

Closed
mbfm opened this issue Oct 19, 2023 · 5 comments
Closed

Rust-Script caching does not work #968

mbfm opened this issue Oct 19, 2023 · 5 comments
Assignees
Milestone

Comments

@mbfm
Copy link

mbfm commented Oct 19, 2023

Describe The Bug

The built-in caching of rust-script does not seem to work when executed from cargo-make. This means for each execution of a Rust-scripted cargo-make task, the Rust code always needs to be re-compiled. This leads to a major increase in execution times, especially with multiple Rust-scripted tasks and when using dependencies in them.

My assumption is that this is caused by cargo-make placing each Rust snippet into a randomized path before passing it to rust-script (e.g. /tmp/fsio_EZBn6pD1kk.rs). Due to the file names always changing, the caching mechanism of rust-script is effectively bypassed.

This also leads to an enormous amount of cached builds being stored by rust-script underneath ~/.cache/rust-script/binaries/ (currently at 245 GB on my dev laptop).

To Reproduce

Use e.g. this task definition:

[tasks.rust-script-check]
script_runner = "@rust"
script = '''
//! ```cargo
//! [dependencies]
//! envmnt = "*"
//! ```
fn main() {
    println!("{:?}", std::env::current_exe());
}
'''

Then run this task two or more times. Due to the dependency, compiling takes a noticeable amount of time. The println!() indicates when compiling is finished, and it shows that each time, the actual executable is different (i.e. not re-using a cached executable).

@sagiegurari
Copy link
Owner

@mbfm previously i used a different (unmaintained now) crate which i think hashed the code and cache was based on that so caching worked. seems the alternatives i used do not do that.
so i can maybe hash the code and define the directory via this hash so caching will work again.

@sagiegurari
Copy link
Owner

@mbfm can you check the dev branch 0.37.3 and verify this is now working as expected (faster)?
basically the scripts are now written to the target directory and reused to enable faster execution.

@sagiegurari
Copy link
Owner

@mbfm this is now officially released

@mbfm
Copy link
Author

mbfm commented Oct 30, 2023

Awesome, thanks.

Anecdotally, cached execution time for one of our somewhat more complex flows (runs 4 Rust scripts) dropped from 50 seconds to less than 5 seconds.

@sagiegurari
Copy link
Owner

@mbfm thanks for checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants