pixi icon indicating copy to clipboard operation
pixi copied to clipboard

perf: cache activation environment variables

Open borchero opened this issue 1 year ago • 7 comments

Motivation

Resolves #973.

This PR obviously misses some tests, I just wanted to check in early if this goes into the right direction.

borchero avatar Aug 18 '24 19:08 borchero

Thanks @borchero, cool feature. I'm a little worried about the invalidation as on windows this might not work as well. @baszalmstra can you give your feedback.

ruben-arts avatar Aug 19 '24 06:08 ruben-arts

I like this a lot! Thanks for the contribution.

The biggest problem is that some of these environment variables are initialized from system environment variables. For instance, when you add the compiler activation scripts on Windows the path to a specific MSVC compiler is added. However, when a new update of the compiler is installed (which happens from time to time) this path is no longer valid. The same goes for the system PATH variable, this can be updated but the changes would not be reflected in our cached entry.

I think it would be good to add a time-to-live to the cache entry so that the cache entry will be recomputed after a period of time (30 minutes?).

Maybe we can also invalidate the cache if certain environment variables no longer match what they were when the cache was created? I think the PATH variable is a prime example.

The entries should also be cleared on pixi clean, or is that already the case?

baszalmstra avatar Aug 19 '24 15:08 baszalmstra

I think it would be good to add a time-to-live to the cache entry so that the cache entry will be recomputed after a period of time (30 minutes?).

I'm not sure this is the best solution to be honest. I think it introduces hard-to-debug issues that are non-deterministic over time :eyes:

That being said, I think it's important that we identify a set of items that need to be hashed. The lockfile is an obvious one. Using the PATH environment variable also makes sense to me. Eventually, I'm unsure how one can get around non-deterministic activation scripts (such as the compiler activation scripts you mentioned) :eyes:

borchero avatar Aug 19 '24 16:08 borchero

Yeah I agree a TTL is very much suboptimal.

Maybe we can start by identifying a larger set of environment variables to use as input? I guess its less anoying when you have a stale cache than an invalid one.

baszalmstra avatar Aug 19 '24 16:08 baszalmstra

Maybe we can start by identifying a larger set of environment variables to use as input

That'd be great :smile: do you have any proposal where to start with this? I personally know very little about Windows and that's usually where most issues arise 🙃

borchero avatar Aug 19 '24 16:08 borchero

If you start the implementation and have a list somewhere Ill investigate what we need on windows!

baszalmstra avatar Aug 19 '24 18:08 baszalmstra

@borchero are you planning to work on this?

ruben-arts avatar Sep 16 '24 14:09 ruben-arts

Sorry I didn't get back here @ruben-arts, I did not get the opportunity to work on this recently. Thanks for taking over the PR! I will close this one :)

borchero avatar Oct 29 '24 11:10 borchero