Skip to content

Conversation

@jorisdral
Copy link
Collaborator

@jorisdral jorisdral commented Oct 22, 2024

This is a follow-up to #426

The best description of the approach can be found in the code, in the GHC-style note Note [Credits]

@jorisdral jorisdral force-pushed the jdral/scheduled-merges branch 6 times, most recently from bb95545 to 27107f3 Compare October 29, 2024 13:41
Base automatically changed from jdral/scheduled-merges to main October 29, 2024 15:56
@jorisdral jorisdral marked this pull request as draft October 29, 2024 16:23
@jorisdral jorisdral force-pushed the jdral/batch-merge-work branch 2 times, most recently from 0d7efcb to 5309353 Compare October 31, 2024 15:38
@jorisdral jorisdral marked this pull request as ready for review October 31, 2024 16:27
Copy link
Collaborator

@mheinzel mheinzel left a comment

Choose a reason for hiding this comment

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

Looks good, nice documentation! Just a few points to discuss.

@jorisdral jorisdral force-pushed the jdral/batch-merge-work branch 4 times, most recently from 0d7e461 to 4837e51 Compare November 5, 2024 15:50
Copy link
Collaborator

@mheinzel mheinzel left a comment

Choose a reason for hiding this comment

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

Looks good, but some additional questions.

Copy link
Collaborator

@mheinzel mheinzel left a comment

Choose a reason for hiding this comment

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

I think the naming can be clarified a bit, but should work!

@jorisdral jorisdral force-pushed the jdral/batch-merge-work branch from c5cc13a to 78d6413 Compare November 7, 2024 12:36
Copy link
Collaborator

@mheinzel mheinzel left a comment

Choose a reason for hiding this comment

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

I think this is alright now. Just some small tweaks.

Copy link
Collaborator

@mheinzel mheinzel left a comment

Choose a reason for hiding this comment

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

I also think the scaled/unscaled credit distinction could be a little clearer in some places, but this will improve as soon as we move MergingRun into its own module. In there, we will always consider scaled credits. In MergeSchedule we talk about unscaled credits, only converting at the end to call MergingRun.supplyMergeCredits.


data SnapMergingRun =
SnapMergingRun !MergePolicyForLevel !NumRuns !SnapMergingRunState
SnapMergingRun !MergePolicyForLevel !NumRuns !NumEntries !UnspentCredits !MergeKnownCompleted !SnapMergingRunState
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to snapshot the MergeKnownCompleted? It's like a cache, we can just reconstruct it from the SnapMergingRunState.

Copy link
Collaborator Author

@jorisdral jorisdral Nov 8, 2024

Choose a reason for hiding this comment

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

I've thought about this as well, and I think both with and without storing it here works. It just means we can skip a bit of work now

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd rather keep the snapshot format lean. This would just mean two more lines of code in opening a snapshot and even save one when creating it I think, or are you referring to some other work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I understand your point, but I'm going to change this code later anyway, so I'll keep it as is and follow up with refactorings

@jorisdral jorisdral force-pushed the jdral/batch-merge-work branch from 78d6413 to ea34fe1 Compare November 8, 2024 09:59
Copy link
Collaborator

@mheinzel mheinzel left a comment

Choose a reason for hiding this comment

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

I think some previous comments are still unresolved, but no blockers.

Comment on lines +1248 to +1250
mergeKnownCompleted <- readMutVar mergeKnownCompletedVar
-- The merge is not guaranteed to be complete.
when (mergeKnownCompleted == MergeMaybeCompleted) $ do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think using the cache matters much here (this only happens once per merge). To keep complexity low, I would only use it on the hot path.

Copy link
Collaborator Author

@jorisdral jorisdral Nov 8, 2024

Choose a reason for hiding this comment

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

I'd argue that it decreases complexity: the cached value has a simple correctness argument, so checking it here means we can skip the more complex bit of trying to finish a (maybe) incomplete merge

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, we need to have the branch that finishes an incomplete merge either way. So this just adds an additional branch. But I don't mind much, all good.

This is done to make it clear that there is a difference between progressing the
merge until there are no more inputs to merge (`Done`), and converting the merge
into an output run (`Complete`).
See `Note [Credits]`
@jorisdral jorisdral force-pushed the jdral/batch-merge-work branch from 0f1b0f9 to 9c4dd1f Compare November 8, 2024 14:52
@jorisdral jorisdral enabled auto-merge November 8, 2024 14:53
@jorisdral jorisdral added this pull request to the merge queue Nov 8, 2024
Merged via the queue into main with commit d45f32c Nov 8, 2024
24 checks passed
@jorisdral jorisdral deleted the jdral/batch-merge-work branch November 8, 2024 15:45
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.

3 participants