Reduce Windows desktop format, opening and edit latency
This commit is contained in:
1 parent
4655f8a3c9
commit
830292b9b6
15 files changed
+1006
-167
No files matched your search
@@ -25,8 +25,8 @@ pub(super) struct EditorFormat {
|
||||
}
|
||||
|
||||
struct FormatPreparation {
|
||||
lock: Mutex<()>,
|
||||
build: Box<dyn Fn() -> Result<(), String> + Send + Sync>,
|
||||
ready: Mutex<bool>,
|
||||
prepare: Box<dyn Fn() -> Result<(), String> + Send + Sync>,
|
||||
}
|
||||
|
||||
impl EditorFormat {
|
||||
@@ -41,23 +41,36 @@ impl EditorFormat {
|
||||
profile: InputProfile,
|
||||
build: impl Fn() -> Result<(), String> + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
image,
|
||||
manifest,
|
||||
profile,
|
||||
compiler: NativeCompiler::default(),
|
||||
preparation: Some(Arc::new(FormatPreparation {
|
||||
lock: Mutex::new(()),
|
||||
build: Box::new(build),
|
||||
})),
|
||||
}
|
||||
let output = image.clone();
|
||||
Self::prepare_on_open(image, manifest, profile, move || {
|
||||
if !output.is_file() {
|
||||
build()?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub(super) fn prepare_on_open(
|
||||
image: PathBuf,
|
||||
manifest: PathBuf,
|
||||
profile: InputProfile,
|
||||
prepare: impl Fn() -> Result<(), String> + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
let mut format = Self::prepared(image, manifest, profile);
|
||||
format.preparation = Some(Arc::new(FormatPreparation {
|
||||
ready: Mutex::new(false),
|
||||
prepare: Box::new(prepare),
|
||||
}));
|
||||
format
|
||||
}
|
||||
|
||||
pub(super) fn ensure(&self) -> Result<(), String> {
|
||||
if let Some(preparation) = &self.preparation {
|
||||
let _lock = preparation.lock.lock().unwrap();
|
||||
if !self.image.is_file() {
|
||||
(preparation.build)()?;
|
||||
let mut ready = preparation.ready.lock().unwrap();
|
||||
if !*ready || !self.image.is_file() {
|
||||
(preparation.prepare)()?;
|
||||
*ready = true;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -100,10 +113,10 @@ impl Library {
|
||||
}
|
||||
|
||||
pub(super) fn prewarm_format(&self) {
|
||||
// Decode ready formats in the background. A first launch can show
|
||||
// the library while the selected project's missing format is built.
|
||||
// Decode caller-supplied formats in the background. Windows bundles
|
||||
// defer verification and decoding until a project selects a profile.
|
||||
for format in std::iter::once(&self.primary).chain(self.unicode.iter()) {
|
||||
if !format.image.is_file() {
|
||||
if format.preparation.is_some() || !format.image.is_file() {
|
||||
continue;
|
||||
}
|
||||
let compiler = format.compiler.clone();
|
||||
|
||||
Reference in new issue
Block a user