mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 13:39:12 +00:00
9ecc0a90b1
This PR includes a BREAKING CHANGE. It enables you to create containers before attaching them to the document, making the API more intuitive and straightforward. A container can be either attached to a document or detached. When it's detached, its history/state does not persist. You can attach a container to a document by inserting it into an attached container. Once a container is attached, its state, along with all of its descendants's states, will be recreated in the document. After attaching, the container and its descendants, will each have their corresponding "attached" version of themselves? When a detached container x is attached to a document, you can use x.getAttached() to obtain the corresponding attached container.
48 lines
1.5 KiB
Rust
48 lines
1.5 KiB
Rust
use criterion::{criterion_group, criterion_main, Criterion};
|
|
#[cfg(feature = "test_utils")]
|
|
mod event {
|
|
use super::*;
|
|
|
|
use loro_internal::{ListHandler, LoroDoc};
|
|
use std::sync::Arc;
|
|
|
|
fn create_sub_container(handler: ListHandler, children_num: usize) -> Vec<ListHandler> {
|
|
let mut ans = vec![];
|
|
for idx in 0..children_num {
|
|
let child_handler = handler
|
|
.insert_container(idx, ListHandler::new_detached())
|
|
.unwrap();
|
|
ans.push(child_handler);
|
|
}
|
|
ans
|
|
}
|
|
|
|
pub fn resolved_container(c: &mut Criterion) {
|
|
let mut b = c.benchmark_group("resolved");
|
|
b.sample_size(10);
|
|
b.bench_function("subContainer in event", |b| {
|
|
let children_num = 80;
|
|
let deep = 3;
|
|
b.iter(|| {
|
|
let mut loro = LoroDoc::default();
|
|
loro.start_auto_commit();
|
|
loro.subscribe_root(Arc::new(|_e| {}));
|
|
let mut handlers = vec![loro.get_list("list")];
|
|
for _ in 0..deep {
|
|
handlers = handlers
|
|
.into_iter()
|
|
.flat_map(|h| create_sub_container(h, children_num))
|
|
.collect();
|
|
}
|
|
})
|
|
});
|
|
}
|
|
}
|
|
|
|
pub fn dumb(_c: &mut Criterion) {}
|
|
|
|
#[cfg(feature = "test_utils")]
|
|
criterion_group!(benches, event::resolved_container);
|
|
#[cfg(not(feature = "test_utils"))]
|
|
criterion_group!(benches, dumb);
|
|
criterion_main!(benches);
|