Experiment with verified child segment continuation reuse

This commit is contained in:
gloamxun committed 2026-11-29 11:36:21 +08:00
1 parent 51db480b34
commit 64adf51b20
9 files changed
+247 -23

No files matched your search

+56 -3
View File
@@ -51,7 +51,7 @@ struct CachedCheckpoint {
guard: PrefixInputGuard,
replay_count: usize,
slots: Capture,
child_boundary: Option<crate::native_job::ReplayBoundary>,
}
struct CompletedExecution {
@@ -374,6 +374,12 @@ impl<'a> CapturedEntries<'a> {
{
return;
}
let child_boundary = match slots {
Capture::Nested { interval: 0, .. } => guard.nested_source.as_ref()
.filter(|source| source.observed_size.is_some())
.map(|source| host.files().replay_boundary_with_child(Some(&source.path))),
_ => None,
};
self.retain(
slots,
Arc::new(CachedCheckpoint {
@@ -381,6 +387,7 @@ impl<'a> CapturedEntries<'a> {
guard,
replay_count: calls.len(),
slots,
child_boundary,
}),
);
self.changed = true;
@@ -678,6 +685,37 @@ impl PublishedCheckpoints {
}
impl CheckpointSet {
fn advance_child(&self, current: &CachedCheckpoint) -> Option<(EntryCheckpoint, Option<Capture>)> {
let boundary = current.child_boundary.as_ref()?;
let child = current.guard.nested_source.as_ref()?;
let Capture::Nested { file, interval: 0 } = current.slots else { return None; };
let previous = self.entries.iter().find(|candidate| {
matches!(candidate.slots, Capture::Nested { interval: 0, .. })
&& candidate.entry.frontier() == current.entry.frontier()
&& candidate.replay_count == current.replay_count
&& candidate.child_boundary.as_ref() == Some(boundary)
&& candidate.guard.nested_source.as_ref().is_some_and(|old| {
old.path == child.path && old.observed_size != child.observed_size
})
})?;
self.entries.iter().rev().find_map(|later| {
if !matches!(later.slots, Capture::Nested { interval: 1, .. })
|| later.replay_count != previous.replay_count
|| !later.guard.nested_source.as_ref().is_some_and(|old| old.path == child.path)
{
return None;
}
let advanced = current.entry.advance_within_child(&previous.entry, &later.entry)?;
let bytes = usize::try_from(child.observed_size?).ok()?;
// A valid advance can land before the new midpoint. Leave the
// later slot available so the current run can capture it there.
let retain = (advanced.frontier() > bytes.div_ceil(NESTED_INTERVALS)
&& advanced.frontier() < bytes)
.then_some(Capture::Nested { file, interval: 1 });
Some((advanced, retain))
})
}
fn reserve_body(&self) -> Option<Arc<Self>> {
// The reserve holds only recent shipped checkpoints and the host
// call prefix they independently require.
@@ -886,6 +924,20 @@ impl SelectedCheckpoint {
|slots, entry, host| {
let entry = Arc::new(entry);
captures.capture(slots, entry.clone(), host);
if let Capture::Nested { file, interval: 0 } = slots
&& let Some(current) = captures.nested[file][0].as_ref()
&& Arc::ptr_eq(&current.entry, &entry)
&& let Some((advanced, slots)) = self.set.advance_child(current)
{
let advanced = Arc::new(advanced);
let reused = advanced.completed_steps() - entry.completed_steps();
if let Some(slots) = slots {
captures.capture(slots, advanced.clone(), host);
}
work.reused_steps += reused;
work.reused_suffix_steps += reused;
return CheckpointDecision::Advance(advanced);
}
let Capture::Settled { page, .. } = slots else {
return CheckpointDecision::Continue;
};
@@ -916,8 +968,9 @@ impl SelectedCheckpoint {
*suffix_failure = Some((error.clone(), discarded));
return CheckpointDecision::ReplayFailed(error);
}
work.reused_suffix_steps = execution.steps - entry.completed_steps();
work.reused_steps += work.reused_suffix_steps;
let reused = execution.steps - entry.completed_steps();
work.reused_suffix_steps += reused;
work.reused_steps += reused;
work.replayed_calls += calls.len();
CheckpointDecision::Reuse(Box::new(execution))
},