From b74ab34f79e5e8dd1a9516e311e12648f45b2cd6 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Thu, 8 Dec 2022 20:01:06 +0800 Subject: [PATCH] chore(wasm): make build parallel --- crates/loro-core/src/log_store.rs | 5 +---- .../loro-core/src/log_store/encode_updates.rs | 18 ++++-------------- crates/loro-core/src/log_store/import.rs | 1 - crates/loro-wasm/scripts/build.ts | 8 ++++---- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/crates/loro-core/src/log_store.rs b/crates/loro-core/src/log_store.rs index 7d0f0128..3109cfee 100644 --- a/crates/loro-core/src/log_store.rs +++ b/crates/loro-core/src/log_store.rs @@ -12,7 +12,6 @@ use std::{ marker::PhantomPinned, sync::{Arc, Mutex, MutexGuard, RwLock}, }; -use tracing::debug; use fxhash::FxHashMap; @@ -351,7 +350,6 @@ impl LogStore { self.reg.get_or_create_container_idx(container) } - // TODO: this feels like a dumb way to bypass lifetime issue, but I don't have better idea right now :( #[inline(always)] pub(crate) fn with_hierarchy(&mut self, f: F) -> R where @@ -359,8 +357,7 @@ impl LogStore { { let h = self.hierarchy.clone(); let mut h = h.lock().unwrap(); - let result = f(self, &mut h); - result + f(self, &mut h) } pub fn to_json(&self) -> LoroValue { diff --git a/crates/loro-core/src/log_store/encode_updates.rs b/crates/loro-core/src/log_store/encode_updates.rs index a8d94f45..e277c7f8 100644 --- a/crates/loro-core/src/log_store/encode_updates.rs +++ b/crates/loro-core/src/log_store/encode_updates.rs @@ -185,30 +185,20 @@ fn convert_encoded_to_changes(changes: EncodedClientChanges) -> Vec Result, LoroError> { - debug!("Inner Export Updates"); match self.log_store.try_read() { - Ok(x) => { - debug!("get lock!"); - x.export_updates(from) - } - Err(_) => { - debug!("failed to get lock Err"); - Err(LoroError::LockError) - } + Ok(x) => x.export_updates(from), + Err(_) => Err(LoroError::LockError), } } pub fn import_updates(&mut self, input: &[u8]) -> Result<(), LoroError> { - debug_log::group!("Import at {}", self.client_id()); let ans = self.log_store.write().unwrap().import_updates(input); - let ans = match ans { + match ans { Ok(events) => { self.notify(events); Ok(()) } Err(err) => Err(LoroError::DecodeError(err.to_string().into_boxed_str())), - }; - debug_log::group_end!(); - ans + } } } diff --git a/crates/loro-core/src/log_store/import.rs b/crates/loro-core/src/log_store/import.rs index 472d7887..50f9a66a 100644 --- a/crates/loro-core/src/log_store/import.rs +++ b/crates/loro-core/src/log_store/import.rs @@ -1,4 +1,3 @@ -use crate::event::Path; use crate::LogStore; use crate::{ container::registry::ContainerIdx, diff --git a/crates/loro-wasm/scripts/build.ts b/crates/loro-wasm/scripts/build.ts index 723a69fa..f1b18dd0 100644 --- a/crates/loro-wasm/scripts/build.ts +++ b/crates/loro-wasm/scripts/build.ts @@ -30,9 +30,9 @@ async function build() { return; } - for (const target of TARGETS) { - await buildTarget(target); - } + await Promise.all(TARGETS.map(target => { + return buildTarget(target); + })); console.log( "✅", @@ -71,7 +71,7 @@ function genCommands(target: string): string[] { return [ `rm -rf ./${target}`, `wasm-bindgen --weak-refs --target ${target} --out-dir ${target} ../../target/wasm32-unknown-unknown/${target_dir}/loro_wasm.wasm`, - // ...(profile == "dev" ? [] : [`wasm-opt -O4 ${target}/loro_wasm_bg.wasm -o ${target}/loro_wasm_bg.wasm`]), + ...(profile == "dev" ? [] : [`wasm-opt -O4 ${target}/loro_wasm_bg.wasm -o ${target}/loro_wasm_bg.wasm`]), ]; }