Reduce and measure native suffix convergence work
This commit is contained in:
1 parent
c008c52964
commit
b081c951af
10 files changed
+330
-97
No files matched your search
@@ -2,6 +2,7 @@ use super::super::{
|
||||
source_relocation::SourceRelocation, source_relocation_events::EventRelocation,
|
||||
};
|
||||
use super::*;
|
||||
use std::time::{Duration, Instant};
|
||||
mod material;
|
||||
mod relocate;
|
||||
use material::MaterialReuse;
|
||||
@@ -89,6 +90,15 @@ impl InputFrame {
|
||||
}
|
||||
}
|
||||
|
||||
/// Work done inside an observed suffix splice. A rejected candidate can
|
||||
/// contribute to the checks it reached.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct SuffixKernelTimings {
|
||||
pub state_comparison: Duration,
|
||||
pub retained_accounting: Duration,
|
||||
pub suffix_assembly: Duration,
|
||||
}
|
||||
|
||||
/// Source coordinates for the shipouts copied from a moved execution suffix.
|
||||
pub struct RelocatedShipoutSuffix {
|
||||
first_page: usize,
|
||||
@@ -125,6 +135,16 @@ impl EntryCheckpoint {
|
||||
&self,
|
||||
prior: &Self,
|
||||
completed: &Execution,
|
||||
) -> Option<(Execution, Option<RelocatedShipoutSuffix>)> {
|
||||
self.splice_settled_suffix_observed(prior, completed, None)
|
||||
}
|
||||
|
||||
/// Splice a completed suffix and optionally record its kernel checks.
|
||||
pub fn splice_settled_suffix_observed(
|
||||
&self,
|
||||
prior: &Self,
|
||||
completed: &Execution,
|
||||
mut timings: Option<&mut SuffixKernelTimings>,
|
||||
) -> Option<(Execution, Option<RelocatedShipoutSuffix>)> {
|
||||
if self.entry != self.active_source
|
||||
|| prior.entry != prior.active_source
|
||||
@@ -176,7 +196,9 @@ 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 !same_kernel_continuation(current, old, moved.as_mut()) {
|
||||
if !measure(timings.as_deref_mut().map(|timings| &mut timings.state_comparison), || {
|
||||
same_kernel_continuation(current, old, moved.as_mut())
|
||||
}) {
|
||||
return None;
|
||||
}
|
||||
let offset = StepOffset::new(old.steps, current.steps);
|
||||
@@ -190,47 +212,52 @@ impl EntryCheckpoint {
|
||||
sources[self.entry] = current.sources[self.entry].clone();
|
||||
let tail = completed.events.get(old.events.len()..)?;
|
||||
if completed.accounts_event_history
|
||||
&& !current.equivalent_accounting_history_with_entry_sizes(old, entry_sizes)
|
||||
&& !measure(timings.as_deref_mut().map(|timings| &mut timings.retained_accounting), || {
|
||||
current.equivalent_accounting_history_with_entry_sizes(old, entry_sizes)
|
||||
})
|
||||
{
|
||||
return None;
|
||||
}
|
||||
// The joined events are published results. Resumption always starts
|
||||
// from a live checkpoint, whose original shared allocations stay intact.
|
||||
let mut execution = Execution {
|
||||
format_dumped: completed.format_dumped,
|
||||
format_pdf_images: completed.format_pdf_images.clone(),
|
||||
job_name: completed.job_name.clone(),
|
||||
interaction_mode: completed.interaction_mode,
|
||||
native_page: completed.native_page.clone(),
|
||||
split_discards: completed.split_discards.clone(),
|
||||
after_assignment: completed.after_assignment.clone(),
|
||||
events: current.events.clone().into_vec(),
|
||||
state: completed.state.clone(),
|
||||
io: completed.io.clone(),
|
||||
input_position: completed.input_position,
|
||||
paragraph_mode: completed.paragraph_mode,
|
||||
sources,
|
||||
stream_sources: completed.stream_sources.clone(),
|
||||
generated_inputs: completed.generated_inputs.clone(),
|
||||
reads: completed.reads.clone(),
|
||||
incoming_state: completed.incoming_state,
|
||||
outgoing_state: completed.outgoing_state,
|
||||
steps,
|
||||
reads_event_history: false,
|
||||
accounts_event_history: completed.accounts_event_history,
|
||||
};
|
||||
if let Some((moved, sizes)) = moved.as_mut().zip(entry_sizes) {
|
||||
relocate::append_suffix(&mut execution, tail, offset, moved, sizes, old.sources.len())?;
|
||||
if execution.state != completed.state {
|
||||
execution.outgoing_state = execution.state.fingerprint();
|
||||
let execution = measure(timings.map(|timings| &mut timings.suffix_assembly), || {
|
||||
let mut execution = Execution {
|
||||
format_dumped: completed.format_dumped,
|
||||
format_pdf_images: completed.format_pdf_images.clone(),
|
||||
job_name: completed.job_name.clone(),
|
||||
interaction_mode: completed.interaction_mode,
|
||||
native_page: completed.native_page.clone(),
|
||||
split_discards: completed.split_discards.clone(),
|
||||
after_assignment: completed.after_assignment.clone(),
|
||||
events: current.events.clone().into_vec(),
|
||||
state: completed.state.clone(),
|
||||
io: completed.io.clone(),
|
||||
input_position: completed.input_position,
|
||||
paragraph_mode: completed.paragraph_mode,
|
||||
sources,
|
||||
stream_sources: completed.stream_sources.clone(),
|
||||
generated_inputs: completed.generated_inputs.clone(),
|
||||
reads: completed.reads.clone(),
|
||||
incoming_state: completed.incoming_state,
|
||||
outgoing_state: completed.outgoing_state,
|
||||
steps,
|
||||
reads_event_history: false,
|
||||
accounts_event_history: completed.accounts_event_history,
|
||||
};
|
||||
if let Some((moved, sizes)) = moved.as_mut().zip(entry_sizes) {
|
||||
relocate::append_suffix(&mut execution, tail, offset, moved, sizes, old.sources.len())?;
|
||||
if execution.state != completed.state {
|
||||
execution.outgoing_state = execution.state.fingerprint();
|
||||
}
|
||||
} else if offset.is_identity() {
|
||||
execution.events.extend_from_slice(tail);
|
||||
} else {
|
||||
for event in tail {
|
||||
execution.events.push(offset_event_steps(event, offset)?);
|
||||
}
|
||||
}
|
||||
} else if offset.is_identity() {
|
||||
execution.events.extend_from_slice(tail);
|
||||
} else {
|
||||
for event in tail {
|
||||
execution.events.push(offset_event_steps(event, offset)?);
|
||||
}
|
||||
}
|
||||
Some(execution)
|
||||
})?;
|
||||
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.
|
||||
@@ -362,6 +389,15 @@ impl EntryCheckpoint {
|
||||
}
|
||||
}
|
||||
|
||||
fn measure<T>(elapsed: Option<&mut Duration>, action: impl FnOnce() -> T) -> T {
|
||||
let started = elapsed.is_some().then(Instant::now);
|
||||
let value = action();
|
||||
if let (Some(elapsed), Some(started)) = (elapsed, started) {
|
||||
*elapsed += started.elapsed();
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn offset_event_steps(event: &Event, offset: StepOffset) -> Option<Event> {
|
||||
match event {
|
||||
Event::Statistics(report) => Some(Event::Statistics(Box::new(report.with_step_offset(offset)?))),
|
||||
@@ -497,17 +533,15 @@ fn same_kernel_continuation(
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let map = relocation.as_ref().map(|context| context.map());
|
||||
let relocated;
|
||||
let prior = if let Some(context) = relocation {
|
||||
relocated = match relocate::kernel_continuation(prior, context) {
|
||||
Some(executor) => executor,
|
||||
None => return false,
|
||||
};
|
||||
&relocated
|
||||
} else {
|
||||
prior
|
||||
};
|
||||
if !current.xdv_annotations.same_idle_state(&prior.xdv_annotations)
|
||||
|| !current.xdv_text.same_state(&prior.xdv_text)
|
||||
|| !current.pdf_navigation_geometry.same_state(&prior.pdf_navigation_geometry)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if let Some(relocation) = relocation {
|
||||
return relocate::same_kernel_provenance(current, prior, relocation).unwrap_or(false);
|
||||
}
|
||||
current.state == prior.state
|
||||
&& current.generated_inputs == prior.generated_inputs
|
||||
&& current.conditionals == prior.conditionals
|
||||
@@ -520,16 +554,9 @@ fn same_kernel_continuation(
|
||||
&& current.native_page == prior.native_page
|
||||
&& current.split_discards == prior.split_discards
|
||||
&& current.pending_shipouts == prior.pending_shipouts
|
||||
&& current
|
||||
.xdv_annotations
|
||||
.same_idle_state(&prior.xdv_annotations)
|
||||
&& current.xdv_text.same_state(&prior.xdv_text)
|
||||
&& current
|
||||
.pdf_navigation_geometry
|
||||
.same_state(&prior.pdf_navigation_geometry)
|
||||
&& current
|
||||
.inputs
|
||||
.iter()
|
||||
.zip(&prior.inputs)
|
||||
.all(|(a, b)| a.same_at_shipout(b, map))
|
||||
.all(|(a, b)| a.same_at_shipout(b, None))
|
||||
}
|
||||
Reference in new issue
Block a user