Cache listings of legacy cache dirs #2563
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In a comment in #2562, @7ranceaddic7 noted a significant performance degradation with the current master HEAD version compared to 1.25.3. I audited the changes since then and identified 3 possible causes. This is the first.
Cause
NetFileCache
maintains acachedFiles
string array of files currently in the cache. This list is searched to find files matching a given module's download property.When we consolidated the instance-specific caches in #2535, existing instance-specific cache folders were treated as a fallback if a file was not found in the main cache dir. However, the files in those fallback folders were not added to
cachedFiles
because I wasn't sure how best to do that or if it was necessary. Instead, those files were enumerated from the directories on the fly every time.On closer inspection, this might cause a big slowdown because GUI checks
IsMaybeCachedZip
for every single mod on load, which implies O(n * m) disk operations, where n is the number of mods in the registry and m is the number of files in the legacy caches. If they were added tocachedFiles
instead, then those disk accesses could be avoided and replaced with faster memory accesses.Changes
Now we consolidate all of the files in all of the caches into the single
cachedFiles
array. It turns out this is much easier and simpler than what I did previously. The cache will work the same as before, except faster because it will no longer have to hit the disk for legacy cache dirs.And as long as we're touching this code,
cachedFiles
is now a dictionary mapping from URL hashes to cache entries. This eliminates the need to loop through every entry and check whether it starts with our target hash, which should result in a general performance improvement for cache-related tasks.