Reuse validated checkpoint executors during native preview

This commit is contained in:
gloamxun committed 2026-11-19 11:16:40 +08:00
1 parent 69de8a6599
commit 43231a48c0
8 files changed
+160 -50

No files matched your search

+80 -37
View File
@@ -587,12 +587,19 @@ impl NativeCompiler {
}
struct PreparedJob {
executor: Executor,
executor: Option<Executor>,
format_preparation: Option<FormatPreparation>,
source: SourceFile,
files: Files,
output: PathBuf,
}
#[derive(Clone, Copy, PartialEq, Eq)]
enum KernelPreparation {
Fresh,
Resume,
}
fn prepare(
request: &CompileRequest,
dump: bool,
@@ -608,6 +615,7 @@ fn prepare(
evidence,
None,
EffectMode::Live,
KernelPreparation::Fresh,
)
}
@@ -619,6 +627,7 @@ fn prepare_checked(
evidence: &mut AttemptEvidence,
check_inputs: Option<Box<PreparedInputsCheck<'_>>>,
effects: EffectMode,
kernel: KernelPreparation,
) -> Result<PreparedJob, CompileError> {
use texrra_tex_core::resources::ResourceKind;
check(cancellation)?;
@@ -735,36 +744,61 @@ fn prepare_checked(
FormatPreparation::Decoded,
),
};
let executor = image.fork_job_with_file_dates(
state.profile(),
request.input_profile,
request.time,
request.limits,
&mut world,
read,
date,
)?;
let executor = if kernel == KernelPreparation::Resume {
image.validate_job_inputs(
state.profile(),
request.input_profile,
&mut world,
read,
date,
)?;
None
} else {
Some(image.fork_job_with_file_dates(
state.profile(),
request.input_profile,
request.time,
request.limits,
&mut world,
read,
date,
)?)
};
check(cancellation)?;
if preparation == FormatPreparation::Decoded {
cache.insert(loaded.version, image);
}
(executor, Some(preparation))
}
None => (
FormatImage::decode(&loaded.data)?.new_job_with_file_dates(
state.profile(),
request.input_profile,
request.time,
request.limits,
&mut world,
read,
date,
)?,
Some(FormatPreparation::Decoded),
),
None => {
let image = FormatImage::decode(&loaded.data)?;
let executor = if kernel == KernelPreparation::Resume {
image.validate_job_inputs(
state.profile(),
request.input_profile,
&mut world,
read,
date,
)?;
None
} else {
Some(image.new_job_with_file_dates(
state.profile(),
request.input_profile,
request.time,
request.limits,
&mut world,
read,
date,
)?)
};
(executor, Some(FormatPreparation::Decoded))
}
}
} else {
(Executor::new(state, request.limits), None)
let executor =
(kernel == KernelPreparation::Fresh).then(|| Executor::new(state, request.limits));
(executor, None)
};
check(cancellation)?;
Ok((path, source, executor, output, format_preparation))
@@ -786,11 +820,13 @@ fn prepare_checked(
evidence.inputs = Some(failure.inputs);
CompileError::Host(failure.error)
})?;
let executor = if request.target == Target::Shipouts {
executor.with_native_pages()
} else {
executor
};
let executor = executor.map(|executor| {
if request.target == Target::Shipouts {
executor.with_native_pages()
} else {
executor
}
});
Ok(PreparedJob {
executor,
format_preparation,
@@ -900,6 +936,7 @@ impl CompileJob {
} else {
EffectMode::Live
},
KernelPreparation::Fresh,
)
.map_err(|error| {
if cancellation.is_cancelled() {
@@ -922,20 +959,25 @@ impl CompileJob {
evidence.phase = AttemptPhase::Executing;
let cache = &self.compiler.line_break_cache;
let before = cache.work();
let executor = executor.with_line_break_cache(cache.clone());
let (executed, next_checkpoint) = if let Some(current) = active_checkpoint {
debug_assert!(executor.is_none());
let (executed, next) =
current.resume(self.job, source, files, &mut entry_checkpoint_work)?;
(executed, Some(next))
} else if let Some(cache) = checkpoints {
let (executed, captured) =
cache.capture(&request, self.job, executor, source, files);
if let Some(snapshot) = &captured {
snapshot.report_capture(&mut entry_checkpoint_work);
}
(executed, captured)
} else {
(self.job.run_detailed(executor, source, files), None)
let executor = executor
.expect("fresh native job has an executor")
.with_line_break_cache(cache.clone());
if let Some(cache) = checkpoints {
let (executed, captured) =
cache.capture(&request, self.job, executor, source, files);
if let Some(snapshot) = &captured {
snapshot.report_capture(&mut entry_checkpoint_work);
}
(executed, captured)
} else {
(self.job.run_detailed(executor, source, files), None)
}
};
let execution = match executed {
Ok(execution) => {
@@ -1186,6 +1228,7 @@ fn dump_format_observed(
let result = (|| -> Result<BuiltFormat, CompileError> {
evidence.phase = AttemptPhase::Executing;
let executed = executor
.expect("format dump has a fresh executor")
.with_cancellation(cancellation.clone())
.run_detailed(source, &mut files);
let execution = match executed {