Reuse exact final fingerprints of distinct published states
This commit is contained in:
1 parent
af8f38bb78
commit
841198615a
5 files changed
+104
-29
No files matched your search
@@ -47,7 +47,8 @@ mod specials;
|
||||
mod statistics;
|
||||
mod continuation;
|
||||
pub use continuation::{
|
||||
ClosedSourceChange, RelocatedShipoutSuffix, SuffixKernelTimings, SuffixStateProofTimings,
|
||||
ClosedSourceChange, RelocatedShipoutSuffix, RetainedStateFingerprint, SuffixKernelTimings,
|
||||
SuffixStateProofTimings,
|
||||
};
|
||||
mod xdv_annotation;
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ pub struct SuffixKernelTimings {
|
||||
pub state_proof: Option<SuffixStateProofTimings>,
|
||||
pub retained_accounting: Duration,
|
||||
pub suffix_assembly: Duration,
|
||||
/// Exact matches with an earlier distinct completed state.
|
||||
pub reused_final_fingerprints: usize,
|
||||
}
|
||||
|
||||
/// Work within state comparison, which also checks the surrounding executor.
|
||||
@@ -119,6 +121,7 @@ impl std::ops::AddAssign for SuffixKernelTimings {
|
||||
self.state_comparison += attempt.state_comparison;
|
||||
self.retained_accounting += attempt.retained_accounting;
|
||||
self.suffix_assembly += attempt.suffix_assembly;
|
||||
self.reused_final_fingerprints += attempt.reused_final_fingerprints;
|
||||
if let Some(attempt) = attempt.state_proof {
|
||||
let total = self.state_proof.get_or_insert_with(SuffixStateProofTimings::default);
|
||||
total.attempts += attempt.attempts;
|
||||
@@ -131,6 +134,22 @@ impl std::ops::AddAssign for SuffixKernelTimings {
|
||||
}
|
||||
}
|
||||
|
||||
/// The final state and exact fingerprint of a completed execution.
|
||||
pub struct RetainedStateFingerprint {
|
||||
state: State,
|
||||
fingerprint: u64,
|
||||
}
|
||||
|
||||
impl Execution {
|
||||
/// Retain just the state needed to compare a future splice.
|
||||
pub fn retain_final_state_fingerprint(&self) -> RetainedStateFingerprint {
|
||||
RetainedStateFingerprint {
|
||||
state: self.state.clone(),
|
||||
fingerprint: self.outgoing_state,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Source coordinates for the shipouts copied from a moved execution suffix.
|
||||
pub struct RelocatedShipoutSuffix {
|
||||
first_page: usize,
|
||||
@@ -242,7 +261,7 @@ impl EntryCheckpoint {
|
||||
completed: &Execution,
|
||||
timings: Option<&mut SuffixKernelTimings>,
|
||||
) -> Option<(Execution, Option<RelocatedShipoutSuffix>)> {
|
||||
self.splice_settled_sources(prior, completed, self.entry, 1, timings)
|
||||
self.splice_settled_suffix_with_fingerprint(prior, completed, None, None, timings)
|
||||
}
|
||||
|
||||
/// Reuse a suffix after the caller has verified the actual host reads
|
||||
@@ -256,12 +275,31 @@ impl EntryCheckpoint {
|
||||
prefix_resource_reads: usize,
|
||||
timings: Option<&mut SuffixKernelTimings>,
|
||||
) -> Option<(Execution, Option<RelocatedShipoutSuffix>)> {
|
||||
if prefix_resource_reads == 0
|
||||
|| self.closed_source_change(prior, completed)?.source_id != source_id
|
||||
{
|
||||
return None;
|
||||
}
|
||||
self.splice_settled_sources(prior, completed, source_id, prefix_resource_reads, timings)
|
||||
self.splice_settled_suffix_with_fingerprint(
|
||||
prior, completed, Some((source_id, prefix_resource_reads)), None, timings,
|
||||
)
|
||||
}
|
||||
|
||||
/// Verify a settled suffix with an optional prior state used only for
|
||||
/// its final fingerprint. The usual kernel and host proofs still apply.
|
||||
pub fn splice_settled_suffix_with_fingerprint(
|
||||
&self,
|
||||
prior: &Self,
|
||||
completed: &Execution,
|
||||
closed_source: Option<(usize, usize)>,
|
||||
retained: Option<&RetainedStateFingerprint>,
|
||||
timings: Option<&mut SuffixKernelTimings>,
|
||||
) -> Option<(Execution, Option<RelocatedShipoutSuffix>)> {
|
||||
let (source_id, prefix_resource_reads) = match closed_source {
|
||||
Some((source_id, reads)) => {
|
||||
if reads == 0 || self.closed_source_change(prior, completed)?.source_id != source_id {
|
||||
return None;
|
||||
}
|
||||
(source_id, reads)
|
||||
}
|
||||
None => (self.entry, 1),
|
||||
};
|
||||
self.splice_settled_sources(prior, completed, source_id, prefix_resource_reads, retained, timings)
|
||||
}
|
||||
|
||||
fn splice_settled_sources(
|
||||
@@ -270,6 +308,7 @@ impl EntryCheckpoint {
|
||||
completed: &Execution,
|
||||
source_id: usize,
|
||||
prefix_resource_reads: usize,
|
||||
retained: Option<&RetainedStateFingerprint>,
|
||||
mut timings: Option<&mut SuffixKernelTimings>,
|
||||
) -> Option<(Execution, Option<RelocatedShipoutSuffix>)> {
|
||||
if self.entry != self.active_source
|
||||
@@ -425,7 +464,8 @@ impl EntryCheckpoint {
|
||||
let statistics = SuffixStatistics { steps: offset, boxes: box_offset, retained_history };
|
||||
// The joined events are published results. Resumption always starts
|
||||
// from a live checkpoint, whose original shared allocations stay intact.
|
||||
let execution = measure(timings.map(|timings| &mut timings.suffix_assembly), || {
|
||||
let mut reused_final_fingerprint = false;
|
||||
let execution = measure(timings.as_deref_mut().map(|timings| &mut timings.suffix_assembly), || {
|
||||
let mut events = Vec::with_capacity(current.events.len().checked_add(tail.len())?);
|
||||
events.extend(current.events.iter().cloned());
|
||||
let (reads, dependency_evidence) = splice_dependencies(current, old, completed)?;
|
||||
@@ -460,8 +500,14 @@ impl EntryCheckpoint {
|
||||
&mut execution, tail, &statistics, moved, resize, old.sources.len(),
|
||||
)?;
|
||||
if execution.state != completed.state {
|
||||
execution.outgoing_state = execution.state
|
||||
.fingerprint_with_prior(Some(&completed.state));
|
||||
execution.outgoing_state = if let Some(retained) = retained
|
||||
&& execution.state == retained.state
|
||||
{
|
||||
reused_final_fingerprint = true;
|
||||
retained.fingerprint
|
||||
} else {
|
||||
execution.state.fingerprint_with_prior(Some(&completed.state))
|
||||
};
|
||||
}
|
||||
} else if statistics.is_identity() {
|
||||
execution.events.extend_from_slice(tail);
|
||||
@@ -477,6 +523,9 @@ impl EntryCheckpoint {
|
||||
}
|
||||
Some(execution)
|
||||
})?;
|
||||
if let Some(timings) = timings {
|
||||
timings.reused_final_fingerprints += usize::from(reused_final_fingerprint);
|
||||
}
|
||||
let layout = relocation.map(|map| RelocatedShipoutSuffix {
|
||||
// The executor records one top-level shipout event whenever
|
||||
// this count advances. Form canvases do not enter this sequence.
|
||||
|
||||
@@ -73,7 +73,7 @@ pub use device::{NativeShipout, ShipoutDevice, ShipoutSpecial};
|
||||
pub use diagnostics::{DiagnosticBox, DiagnosticNode, ShowBoxReport};
|
||||
pub use engine::{
|
||||
CheckpointCloneTimings, CheckpointDecision, CheckpointSource, ClosedSourceChange,
|
||||
EntryCheckpoint, Executor, Limits, RelocatedShipoutSuffix, SuffixKernelTimings,
|
||||
EntryCheckpoint, Executor, Limits, RelocatedShipoutSuffix, RetainedStateFingerprint, SuffixKernelTimings,
|
||||
SuffixStateProofTimings,
|
||||
};
|
||||
pub use font_catalog::{
|
||||
|
||||
Reference in new issue
Block a user