diff --git a/Cargo.toml b/Cargo.toml index c66a4d73..861a00a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,6 @@ [workspace] members = ["crates/*"] + + +[profile.release] +lto = true diff --git a/crates/loro-core/Cargo.toml b/crates/loro-core/Cargo.toml index 530990b2..18cbff08 100644 --- a/crates/loro-core/Cargo.toml +++ b/crates/loro-core/Cargo.toml @@ -13,3 +13,4 @@ smartstring = "1.0.1" fxhash = "0.2.1" ring = "0.16.20" moveit = "0.5.0" +pin-project = "1.0.10" diff --git a/crates/loro-core/src/lib.rs b/crates/loro-core/src/lib.rs index d324a1d6..6c13487f 100644 --- a/crates/loro-core/src/lib.rs +++ b/crates/loro-core/src/lib.rs @@ -2,6 +2,7 @@ //! //! #![allow(dead_code, unused_imports, clippy::explicit_auto_deref)] +#![feature(const_pin)] pub mod change; pub mod configure; diff --git a/crates/loro-core/src/log_store.rs b/crates/loro-core/src/log_store.rs index 59fbbbbf..e6bf1039 100644 --- a/crates/loro-core/src/log_store.rs +++ b/crates/loro-core/src/log_store.rs @@ -1,5 +1,6 @@ mod iter; -use std::{collections::BinaryHeap, pin::Pin, ptr::NonNull}; +use pin_project::pin_project; +use std::{collections::BinaryHeap, marker::PhantomPinned, pin::Pin, ptr::NonNull}; use fxhash::FxHashMap; use moveit::New; @@ -37,6 +38,7 @@ impl Default for GcConfig { /// Entry of the loro inner state. /// This is a self-referential structure. So it need to be pinned. +#[pin_project] pub struct LogStore { changes: FxHashMap>, cfg: Configure, @@ -47,6 +49,8 @@ pub struct LogStore { /// CRDT container manager pub(crate) container: ContainerManager, + + _pin: PhantomPinned, } impl LogStore { @@ -63,9 +67,12 @@ impl LogStore { store: NonNull::dangling(), }, frontier: Default::default(), + _pin: PhantomPinned, }); - this.container.store = NonNull::new(this.as_mut().get_mut() as *mut _).unwrap(); + let p = this.as_ref().get_ref(); + let p = p as *const _ as *mut LogStore; + this.container.store = unsafe { NonNull::new_unchecked(p) }; this }