Reduce macro copying during native suffix convergence
This commit is contained in:
1 parent
57c05d9635
commit
c008c52964
9 files changed
+228
-110
No files matched your search
@@ -27,6 +27,7 @@ use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
};
|
||||
pub use texrra_tex_core::resources::{ProjectDefinition, ProjectSnapshot, ProjectVersion};
|
||||
pub use texrra_tex_core::resources::{WorldFailure, WorldObservation};
|
||||
@@ -94,12 +95,30 @@ pub enum CompileStage {
|
||||
Exported,
|
||||
ReadyToPublish,
|
||||
}
|
||||
/// Elapsed work while resuming a native checkpoint after prefix replay.
|
||||
/// The callback slices are disjoint and included in `resume`.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct CheckpointTimings {
|
||||
/// Restoring the executor, running new commands, observing checkpoints,
|
||||
/// and finishing the revision's kernel result.
|
||||
pub resume: Duration,
|
||||
pub capture: Duration,
|
||||
pub suffix_host_validation: Duration,
|
||||
pub suffix_kernel_validation: Duration,
|
||||
pub suffix_host_replay: Duration,
|
||||
/// Collecting the retained checkpoint set after the resumed run.
|
||||
pub retain: Duration,
|
||||
}
|
||||
|
||||
/// Called outside the publication lock. An observer can request a new
|
||||
/// revision or fail without publishing this result. Start/cancel are allowed;
|
||||
/// schedule compilation after the callback returns, rather than recursing.
|
||||
pub trait CompileObserver: Send + Sync {
|
||||
fn stage(&self, revision: u64, stage: CompileStage) -> Result<(), String>;
|
||||
|
||||
/// Observe the work of a resumed native revision before layout begins.
|
||||
fn checkpoint_timings(&self, _revision: u64, _timings: CheckpointTimings) {}
|
||||
|
||||
/// Called for a completed native draft before its staged files are synced
|
||||
/// and installed. The caller can display these pages provisionally. The
|
||||
/// compile result determines whether this revision actually published.
|
||||
|
||||
@@ -7,6 +7,7 @@ use std::{
|
||||
collections::{BTreeMap, BTreeSet, VecDeque},
|
||||
ffi::OsString,
|
||||
path::Path,
|
||||
time::Instant,
|
||||
};
|
||||
use texrra_tex_core::{
|
||||
execution::{CheckpointDecision, CheckpointSource, EntryCheckpoint, RelocatedShipoutSuffix},
|
||||
@@ -956,6 +957,9 @@ impl SelectedCheckpoint {
|
||||
let suffixes = self.set.completion.iter().chain(&self.set.suffix_base);
|
||||
let mut suffix_base = None;
|
||||
let mut reused_layouts = None;
|
||||
let mut timings = CheckpointTimings::default();
|
||||
let timed = request.observer.is_some();
|
||||
let resume_started = timed.then(Instant::now);
|
||||
let result = job
|
||||
.resume_deciding_suffix(
|
||||
&checkpoint.entry,
|
||||
@@ -979,7 +983,9 @@ impl SelectedCheckpoint {
|
||||
},
|
||||
|slots, entry, host| {
|
||||
let entry = Arc::new(entry);
|
||||
captures.capture(slots, entry.clone(), host);
|
||||
measure(&mut timings.capture, timed, || {
|
||||
captures.capture(slots, entry.clone(), host);
|
||||
});
|
||||
let Capture::Settled { page, .. } = slots else {
|
||||
return CheckpointDecision::Continue;
|
||||
};
|
||||
@@ -988,21 +994,25 @@ impl SelectedCheckpoint {
|
||||
};
|
||||
let Some((completed, old, execution, layout)) = suffixes.clone().find_map(|completed| {
|
||||
let old = completed.settled.get(&page)?;
|
||||
if old.call_count != new.call_count
|
||||
|| !new.host.matches_for_suffix(&old.host)
|
||||
|| !can_replay_completed_suffix(completed, request, host.files())
|
||||
{
|
||||
let host_matches = measure(&mut timings.suffix_host_validation, timed, || {
|
||||
old.call_count == new.call_count
|
||||
&& new.host.matches_for_suffix(&old.host)
|
||||
&& can_replay_completed_suffix(completed, request, host.files())
|
||||
});
|
||||
if !host_matches {
|
||||
return None;
|
||||
}
|
||||
let (execution, layout) = entry
|
||||
.splice_settled_suffix_with_layout(&old.entry, &completed.result.execution)?;
|
||||
let (execution, layout) = measure(&mut timings.suffix_kernel_validation, timed, || {
|
||||
entry.splice_settled_suffix_with_layout(&old.entry, &completed.result.execution)
|
||||
})?;
|
||||
Some((completed, old, execution, layout))
|
||||
}) else {
|
||||
return CheckpointDecision::Continue;
|
||||
};
|
||||
let calls = &completed.calls[old.call_count..];
|
||||
let replayed =
|
||||
captures.replay_settled_suffix(page, &entry, old, completed, host, &cancellation);
|
||||
let replayed = measure(&mut timings.suffix_host_replay, timed, || {
|
||||
captures.replay_settled_suffix(page, &entry, old, completed, host, &cancellation)
|
||||
});
|
||||
if let Err(error) = replayed {
|
||||
let discarded = entry.completed_steps().saturating_sub(work.reused_steps);
|
||||
*suffix_failure = Some((error.clone(), discarded));
|
||||
@@ -1027,10 +1037,17 @@ impl SelectedCheckpoint {
|
||||
)
|
||||
.map_err(CompileError::Host)?
|
||||
.ok_or_else(changed_prefix)?;
|
||||
let next = result.as_ref().ok().and_then(|result| {
|
||||
captures.finish(recording, true, result, suffix_base)
|
||||
if let Some(started) = resume_started {
|
||||
timings.resume = started.elapsed();
|
||||
}
|
||||
let next = measure(&mut timings.retain, timed, || {
|
||||
result.as_ref().ok().and_then(|result| captures.finish(recording, true, result, suffix_base))
|
||||
});
|
||||
if result.is_err() {
|
||||
if result.is_ok() {
|
||||
if let Some(observer) = &request.observer {
|
||||
observer.checkpoint_timings(job.revision(), timings);
|
||||
}
|
||||
} else {
|
||||
reused_layouts = None;
|
||||
}
|
||||
if let Some(next) = next {
|
||||
@@ -1042,6 +1059,15 @@ impl SelectedCheckpoint {
|
||||
}
|
||||
}
|
||||
|
||||
fn measure<T>(elapsed: &mut Duration, enabled: bool, action: impl FnOnce() -> T) -> T {
|
||||
let started = enabled.then(Instant::now);
|
||||
let value = action();
|
||||
if let Some(started) = started {
|
||||
*elapsed += started.elapsed();
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn can_replay_completed_suffix(
|
||||
completed: &CompletedExecution,
|
||||
request: &CompileRequest,
|
||||
|
||||
Reference in new issue
Block a user