Prewarm LaTeX format and cache verified project preparation artifacts
This commit is contained in:
1 parent
fdd327eb01
commit
c1742e1c10
10 files changed
+668
-28
No files matched your search
@@ -23,6 +23,7 @@ pub use crate::native_stream::{
|
||||
};
|
||||
use checkpoint_guard::CheckpointCache;
|
||||
pub use checkpoint_guard::EntryCheckpointWork;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
@@ -674,6 +675,27 @@ struct CachedFormat {
|
||||
}
|
||||
|
||||
impl FormatCache {
|
||||
fn prewarm(&self, format: &Path) -> Result<(), CompileError> {
|
||||
let mut cache = self.0.lock().expect("decoded native format cache poisoned");
|
||||
let (path, data) = format
|
||||
.canonicalize()
|
||||
.and_then(|path| std::fs::read(&path).map(|data| (path, data)))
|
||||
.map_err(|error| format!("native format {}: {error}", format.display()))?;
|
||||
let version = ResourceVersion {
|
||||
path,
|
||||
sha256: format!("{:x}", Sha256::digest(&data)),
|
||||
bytes: data.len() as u64,
|
||||
};
|
||||
if !cache.as_ref().is_some_and(|cached| cached.version == version) {
|
||||
*cache = Some(CachedFormat {
|
||||
version,
|
||||
image: Arc::new(FormatImage::decode(&data)?),
|
||||
bindings: Arc::default(),
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get(&self, version: &ResourceVersion) -> Option<CachedFormat> {
|
||||
let cache = self.0.lock().expect("decoded native format cache poisoned");
|
||||
cache
|
||||
@@ -691,6 +713,20 @@ pub struct CompileJob {
|
||||
job: RevisionJob,
|
||||
}
|
||||
impl NativeCompiler {
|
||||
/// Decode the startup format before opening a project. Each job still
|
||||
/// resolves the format and validates its input bindings against its own world.
|
||||
pub fn prewarm_format(&self, format: &Path) -> Result<(), CompileError> {
|
||||
self.format_cache.prewarm(format)
|
||||
}
|
||||
|
||||
/// Create an independent session with access to the same decoded format.
|
||||
pub fn new_session_sharing_format(&self) -> Self {
|
||||
Self {
|
||||
format_cache: self.format_cache.clone(),
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Enable entry-prefix reuse for atomic project shipout jobs. The byte
|
||||
/// position is a lower bound for a physical command boundary to retain.
|
||||
/// Invalidated prefixes use the same full compiler in the same revision.
|
||||
|
||||
Reference in new issue
Block a user