Skip to content

Module cache rebuild logic#5175

Open
graydon wants to merge 6 commits intostellar:masterfrom
graydon:module-cache-rebuild-logic
Open

Module cache rebuild logic#5175
graydon wants to merge 6 commits intostellar:masterfrom
graydon:module-cache-rebuild-logic

Conversation

@graydon
Copy link
Contributor

@graydon graydon commented Mar 12, 2026

This does a little simplification on the arithmetic we were doing to track thresholds of module cache rebuilding, as well as clarifying when we're measuring input vs. output values in the cost model. Also it moves the module cache tests to a separate file, as part of my long term dream to split InvokeHostFunctionTests.cpp into multiple files.

One disappointing part about this is that the tweak above reveals that the ApplyState state-invariant-checking that @SirTyson put in back in #4819 was actually slightly incorrect: the finishPendingCompilation method does actually write to ApplyState when it's in READY_TO_APPLY (it did back then too, it just didn't happen to occur in tests before). I can't think of any really great way to avoid this (the whole point is to defer the implied variable-update/stall until the last moment before we'll need it) besides I guess we could like add in another state? I don't know if that would win much, but I'd be willing to if that's your preference @SirTyson ?

Copilot AI review requested due to automatic review settings March 12, 2026 01:50
@graydon graydon requested a review from SirTyson March 12, 2026 01:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@SirTyson SirTyson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the state transitions, I'm wondering if we should check for recompilation right after mApplyState.markEndOfCommitting();, and if compilation is necessary, transition to the SETTING_UP_STATE. I think semantically this makes the most sense, we aren't ready to apply (because we're setting up our module cache), but we also aren't committing anything. This would allow us to have stronger invariants on finishPendingCompilation, and I think is the most semantically correct. This also helps with our assert when we transition from READY_TO_APPLY -> APPLYING, as we can't enter the APPLYING phase until our compilation is done. What do you think?

@graydon
Copy link
Contributor Author

graydon commented Mar 17, 2026

Looking at the state transitions, I'm wondering if we should check for recompilation right after mApplyState.markEndOfCommitting();, and if compilation is necessary, transition to the SETTING_UP_STATE. I think semantically this makes the most sense, we aren't ready to apply (because we're setting up our module cache), but we also aren't committing anything. This would allow us to have stronger invariants on finishPendingCompilation, and I think is the most semantically correct. This also helps with our assert when we transition from READY_TO_APPLY -> APPLYING, as we can't enter the APPLYING phase until our compilation is done. What do you think?

Yeah, we could try that. I'll see how it goes.

@graydon graydon force-pushed the module-cache-rebuild-logic branch from b474074 to ac5245e Compare March 17, 2026 08:37
@graydon
Copy link
Contributor Author

graydon commented Mar 17, 2026

Looking at the state transitions, I'm wondering if we should check for recompilation right after mApplyState.markEndOfCommitting();, and if compilation is necessary, transition to the SETTING_UP_STATE. I think semantically this makes the most sense, we aren't ready to apply (because we're setting up our module cache), but we also aren't committing anything. This would allow us to have stronger invariants on finishPendingCompilation, and I think is the most semantically correct. This also helps with our assert when we transition from READY_TO_APPLY -> APPLYING, as we can't enter the APPLYING phase until our compilation is done. What do you think?

Yeah, we could try that. I'll see how it goes.

It appears to work. Updated PR with change. Now needs even more careful scrutiny!

@graydon graydon requested a review from SirTyson March 17, 2026 09:15
@graydon graydon force-pushed the module-cache-rebuild-logic branch from ac5245e to 558e73f Compare March 18, 2026 05:33
@graydon
Copy link
Contributor Author

graydon commented Mar 18, 2026

@jayz22 note: I changed the logic back to track and compare the count of modules * number of protocols, systematically. This is actually something we already have a test for and it's more honest about "actual memory pressure" so I think it's probably best to leave that way.

dmkozh
dmkozh previously approved these changes Mar 20, 2026
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.

5 participants