Expose optional checkpoint clone and suffix proof timings

This commit is contained in:
gloamxun committed 2026-12-02 02:38:43 +08:00
1 parent 67396827a9
commit c8f7a0cbe6
7 files changed
+170 -27

No files matched your search

@@ -97,10 +97,40 @@ impl InputFrame {
#[derive(Clone, Copy, Debug, Default)]
pub struct SuffixKernelTimings {
pub state_comparison: Duration,
/// The caller can enable the more detailed checks without changing this path.
pub state_proof: Option<SuffixStateProofTimings>,
pub retained_accounting: Duration,
pub suffix_assembly: Duration,
}
/// Work within state comparison, which also checks the surrounding executor.
#[derive(Clone, Copy, Debug, Default)]
pub struct SuffixStateProofTimings {
pub attempts: usize,
pub matches: usize,
pub relocated_attempts: usize,
pub state_clone: Duration,
pub state_relocation: Duration,
pub exact_equality: Duration,
}
impl std::ops::AddAssign for SuffixKernelTimings {
fn add_assign(&mut self, attempt: Self) {
self.state_comparison += attempt.state_comparison;
self.retained_accounting += attempt.retained_accounting;
self.suffix_assembly += attempt.suffix_assembly;
if let Some(attempt) = attempt.state_proof {
let total = self.state_proof.get_or_insert_with(SuffixStateProofTimings::default);
total.attempts += attempt.attempts;
total.matches += attempt.matches;
total.relocated_attempts += attempt.relocated_attempts;
total.state_clone += attempt.state_clone;
total.state_relocation += attempt.state_relocation;
total.exact_equality += attempt.exact_equality;
}
}
}
/// Source coordinates for the shipouts copied from a moved execution suffix.
pub struct RelocatedShipoutSuffix {
first_page: usize,
@@ -339,9 +369,24 @@ impl EntryCheckpoint {
// Comparison and publication visit some of the same original
// allocations. Keep the checked relocations for this donor only.
let mut moved = relocation.as_ref().map(EventRelocation::new);
if !measure(timings.as_deref_mut().map(|timings| &mut timings.state_comparison), || {
same_kernel_continuation(current, old, moved.as_mut())
}) {
let states_match = if let Some(timings) = timings.as_deref_mut() {
let started = Instant::now();
if let Some(proof) = &mut timings.state_proof {
proof.attempts += 1;
proof.relocated_attempts += usize::from(moved.is_some());
}
let matched = same_kernel_continuation(
current, old, moved.as_mut(), timings.state_proof.as_mut(),
);
if let Some(proof) = &mut timings.state_proof {
proof.matches += usize::from(matched);
}
timings.state_comparison += started.elapsed();
matched
} else {
same_kernel_continuation(current, old, moved.as_mut(), None)
};
if !states_match {
return None;
}
let offset = StepOffset::new(old.steps, current.steps);
@@ -707,6 +752,7 @@ fn same_kernel_continuation(
current: &Executor,
prior: &Executor,
relocation: Option<&mut EventRelocation<'_>>,
timings: Option<&mut SuffixStateProofTimings>,
) -> bool {
// Every field belongs to one of these checks. Adding kernel state requires
// an explicit decision here before a later execution may be skipped.
@@ -824,9 +870,9 @@ fn same_kernel_continuation(
return false;
}
if let Some(relocation) = relocation {
return relocate::same_kernel_provenance(current, prior, relocation).unwrap_or(false);
return relocate::same_kernel_provenance(current, prior, relocation, timings).unwrap_or(false);
}
current.state == prior.state
measure(timings.map(|timings| &mut timings.exact_equality), || current.state == prior.state)
&& current.generated_inputs == prior.generated_inputs
&& current.conditionals == prior.conditionals
&& current.current == prior.current
@@ -5,6 +5,7 @@ pub(super) fn same_kernel_provenance(
current: &Executor,
prior: &Executor,
relocation: &mut EventRelocation<'_>,
mut timings: Option<&mut SuffixStateProofTimings>,
) -> Option<bool> {
let map = relocation.map();
if current.current != map.relocate_span(prior.current)?
@@ -98,9 +99,15 @@ pub(super) fn same_kernel_provenance(
return Some(false);
}
let mut state = prior.state.clone();
state.relocate_source(relocation)?;
Some(current.state == state)
let mut state = measure(
timings.as_deref_mut().map(|timings| &mut timings.state_clone),
|| prior.state.clone(),
);
measure(
timings.as_deref_mut().map(|timings| &mut timings.state_relocation),
|| state.relocate_source(relocation),
)?;
Some(measure(timings.map(|timings| &mut timings.exact_equality), || current.state == state))
}
pub(super) fn append_suffix(