Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block machines: Skip complete identities #1528

Merged
merged 4 commits into from
Jul 3, 2024
Merged

Conversation

georgwiese
Copy link
Collaborator

@georgwiese georgwiese commented Jul 3, 2024

Just like the VmProcessor, with this PR the BlockProcessor never processes an identity again that has been completed.

This should be a slight performance optimization (when the "default" sequence iterator is used), but more importantly it:

Comment on lines -498 to -535
// First check if we already store the value.
// This can happen in the loop detection case, where this function is just called
// to validate the constraints.
if outer_query.left.iter().all(|v| v.is_constant()) {
// All values on the left hand side are known, check if this is a query
// to the last row.
if let Some(row_index) = self.last_latch_row_index() {
let current = &self.get_row(row_index);
let fresh_row = Row::fresh(self.fixed_data, row_index + 1);
let next = if self.latch_row == self.block_size - 1 {
// We don't have the next row, because it would be the first row of the next block.
// We'll use a fresh row instead.
&fresh_row
} else {
self.get_row(row_index + 1)
};

let row_pair = RowPair::new(
current,
next,
row_index,
self.fixed_data,
UnknownStrategy::Unknown,
);

let mut identity_processor = IdentityProcessor::new(self.fixed_data, mutable_state);
if let Ok(result) = identity_processor.process_link(&outer_query, &row_pair) {
if result.is_complete() && result.constraints.is_empty() {
log::trace!(
"End processing block machine '{}' (already solved)",
self.name()
);
return Ok(result);
}
}
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Finally, we can remove this trouble maker! It is very error prone and had to be adjusted many times in the past.

Commit 9b042b2 asserts that it would never reach the return with the new changes (you can see the CI passes on this commit).

Basically, this code checks if the LHS we are getting happens to be exactly what is in the latch row of the last block that was added. But that only happens in practice if the identity is processed even though it was completed already. The VmProcessor already makes sure not to do that, and with this PR the BlockProcessor does too.

@georgwiese georgwiese marked this pull request as ready for review July 3, 2024 16:02
@chriseth chriseth enabled auto-merge July 3, 2024 16:26
@chriseth chriseth added this pull request to the merge queue Jul 3, 2024
Merged via the queue into main with commit c4ded73 Jul 3, 2024
6 checks passed
@chriseth chriseth deleted the skip-complete-identities branch July 3, 2024 17:09
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.

Witgen: Block machines "forget" that they already completed a block
2 participants