Skip to content

Reduce locking and improve concurrency on cache hits - #124

Draft
mezz wants to merge 2 commits into
neoforged:mainfrom
mezz:pr/cache-hit-without-lock
Draft

Reduce locking and improve concurrency on cache hits#124
mezz wants to merge 2 commits into
neoforged:mainfrom
mezz:pr/cache-hit-without-lock

Conversation

@mezz

@mezz mezz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR skips the intermediate-result cache key lock on cache hits.

This approach is similar to double-checked locking, we want to see if we can quickly use a cache hit before we do a full lock. I wrote a big comment on it and a test to try to make the approach more clear.

Improvement

I am trying to speed up the case where I switch branches in my IDE, because I do that a lot when checking various bugs.
I found that this area seems to be one that takes the most time, even though everything is cached, and I think it's because many files are hitting this lock and causing it to be a serial process.

Tests

I added one test to try to replicate switching branches in my IDE. It caches one version of Minecraft, then switches to another, etc, to try to exercise the code and make sure it's not getting blocked on clear cache hits.

Notes

restoreOutputsFromCache used to have a side-effect of creating the intermediate cache directory if it was missing.
I don't know if it really matters, but I moved that to the saveOutputs path instead, so that's always done in the locked section.

@neoforged-pr-publishing

Copy link
Copy Markdown
  • Publish PR to GitHub Packages

@mezz mezz changed the title Reduce locking on concurrency of cache hit path by using Reduce locking and improve concurrency on cache hits Aug 3, 2026
@mezz
mezz marked this pull request as draft August 4, 2026 07:35
mezz added 2 commits August 5, 2026 22:25
this approach is similar to double-checked locking, we want to see if we can quickly use a cache hit before we do a full lock
@mezz
mezz force-pushed the pr/cache-hit-without-lock branch from 459ba75 to 032cc00 Compare August 5, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant