mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 00:28:33 +00:00
#### PR Dependency Tree * **PR #14243** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Batch management API for coordinated document mutations and change tracking. * New document accessors (IDs, state snapshots, change/delete set queries) and subscriber count. * **Chores** * Upgraded Rust edition across packages to 2024. * Repository-wide formatting, stylistic cleanups and test adjustments. * **Breaking Changes** * Removed the Node native bindings package and its JS/TS declarations and tests (no longer published/available). <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
80 lines
2.2 KiB
Rust
80 lines
2.2 KiB
Rust
use std::time::Duration;
|
|
|
|
use criterion::{Criterion, criterion_group, criterion_main};
|
|
use rand::{Rng, SeedableRng};
|
|
|
|
fn operations(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("ops/array");
|
|
group.measurement_time(Duration::from_secs(15));
|
|
|
|
group.bench_function("yrs/insert", |b| {
|
|
let base_text = "test1 test2 test3 test4 test5 test6 test7 test8 test9";
|
|
let mut rng = rand_chacha::ChaCha20Rng::seed_from_u64(1234);
|
|
|
|
let idxs = (0..99)
|
|
.map(|_| rng.random_range(0..base_text.len() as u32))
|
|
.collect::<Vec<_>>();
|
|
b.iter(|| {
|
|
use yrs::{Array, Doc, Transact};
|
|
let doc = Doc::new();
|
|
let array = doc.get_or_insert_array("test");
|
|
|
|
let mut trx = doc.transact_mut();
|
|
for c in base_text.chars() {
|
|
array.push_back(&mut trx, c.to_string());
|
|
}
|
|
for idx in &idxs {
|
|
array.insert(&mut trx, *idx, "test");
|
|
}
|
|
drop(trx);
|
|
});
|
|
});
|
|
|
|
group.bench_function("yrs/insert range", |b| {
|
|
let base_text = "test1 test2 test3 test4 test5 test6 test7 test8 test9";
|
|
let mut rng = rand_chacha::ChaCha20Rng::seed_from_u64(1234);
|
|
|
|
let idxs = (0..99)
|
|
.map(|_| rng.random_range(0..base_text.len() as u32))
|
|
.collect::<Vec<_>>();
|
|
b.iter(|| {
|
|
use yrs::{Array, Doc, Transact};
|
|
let doc = Doc::new();
|
|
let array = doc.get_or_insert_array("test");
|
|
|
|
let mut trx = doc.transact_mut();
|
|
for c in base_text.chars() {
|
|
array.push_back(&mut trx, c.to_string());
|
|
}
|
|
for idx in &idxs {
|
|
array.insert_range(&mut trx, *idx, vec!["test1", "test2"]);
|
|
}
|
|
drop(trx);
|
|
});
|
|
});
|
|
|
|
group.bench_function("yrs/remove", |b| {
|
|
let base_text = "test1 test2 test3 test4 test5 test6 test7 test8 test9";
|
|
|
|
b.iter(|| {
|
|
use yrs::{Array, Doc, Transact};
|
|
let doc = Doc::new();
|
|
let array = doc.get_or_insert_array("test");
|
|
|
|
let mut trx = doc.transact_mut();
|
|
for c in base_text.chars() {
|
|
array.push_back(&mut trx, c.to_string());
|
|
}
|
|
for idx in (base_text.len() as u32)..0 {
|
|
array.remove(&mut trx, idx);
|
|
}
|
|
drop(trx);
|
|
});
|
|
});
|
|
|
|
group.finish();
|
|
}
|
|
|
|
criterion_group!(benches, operations);
|
|
criterion_main!(benches);
|