pyaptly icon indicating copy to clipboard operation
pyaptly copied to clipboard

feat: Replace SystemStateReader.read() with lru_cache

Open Melkor333 opened this issue 2 years ago • 1 comments

Removes the very time intensive SystemStateReader.read() function and use functions that directly return the variables. Solve the caching Problem with lru_cache, which is cleared with ...clear_cache() whenever a respective Command is run. Since the Command already has a provides function with known_dependency_types which pretty much exactly resembles the state variables that should be cached, I wrote a small Command.clear_caches() function which clears caches whenever a Command has been run.

I added some provides definitions so that it should work consistently with the cache resetting.

I also split it up into various "easier to understand" feature-separate commits - they should even run through the tests individually :) You can also read the commit notes to follow my thought process.

FWIW I don't really understand the tests all too well and am not 100% sure I didn't accidentally "break" a test. I'm also not sure if more tests would be necessary to properly test the caching... But it looks very much like my changes are correct.

Melkor333 avatar Apr 12 '24 15:04 Melkor333

BTW. I did a very quick check to see if the tests are faster....

# With changes
real    0m44.300s
user    0m15.974s
sys     0m11.979s

# Without changes
real    1m37.832s
user    0m34.823s
sys     0m28.877s

But the tests are still requiring internet (the ubuntu keyservers AFAIU) and I only let it run a single time. But if the tests themselves only take half the time, I can imagine a great speed up for complex setups. We'll see...

Melkor333 avatar Apr 19 '24 20:04 Melkor333