mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-23 05:24:51 +00:00
perf: skip when matched len < 4
This commit is contained in:
parent
3288bddfb8
commit
d8b51f6acf
4 changed files with 19 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"tasks": {
|
||||
"flame": "CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --example permuted --root",
|
||||
"flame": "CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --example permuted_slow --root",
|
||||
"bench": "cargo bench",
|
||||
"fuzz": "cargo +nightly fuzz run match",
|
||||
"test": "cargo nextest run && cargo test --doc"
|
||||
|
|
|
@ -4,7 +4,8 @@ pub fn main() {
|
|||
let data = include_str!("../benches/permuted.mht");
|
||||
// this simulate the situation in loro snapshot encoding,
|
||||
// where we first encode the state snapshot, then we look up the slices of the ops.
|
||||
let mut bytes = CompactBytes::new();
|
||||
let mut bytes = CompactBytes::with_capacity(data.len());
|
||||
println!("{}", bytes.capacity());
|
||||
bytes.append(&data.as_bytes()[..data.len() / 2]);
|
||||
println!("{}", bytes.as_bytes().len()); // 114275
|
||||
bytes.alloc_advance(&data.as_bytes()[data.len() / 2..]);
|
||||
|
|
11
crates/compact-bytes/examples/permuted_slow.rs
Normal file
11
crates/compact-bytes/examples/permuted_slow.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
use compact_bytes::CompactBytes;
|
||||
use criterion::black_box;
|
||||
|
||||
pub fn main() {
|
||||
let data = include_str!("../benches/permuted.mht");
|
||||
for _ in 0..1000 {
|
||||
let mut bytes = CompactBytes::new();
|
||||
bytes.append(&black_box(data).as_bytes()[..data.len() / 2]);
|
||||
bytes.alloc_advance(&black_box(&data.as_bytes()[data.len() / 2..]));
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ impl CompactBytes {
|
|||
}
|
||||
}
|
||||
|
||||
/// cap must be a power of 2
|
||||
/// cap will be adjusted to a power of 2
|
||||
pub fn with_capacity(cap: usize) -> Self {
|
||||
let cap = cap.max(1024).next_power_of_two();
|
||||
CompactBytes {
|
||||
|
@ -175,6 +175,10 @@ impl CompactBytes {
|
|||
len += 1;
|
||||
}
|
||||
|
||||
if len < 4 {
|
||||
break;
|
||||
}
|
||||
|
||||
if len > max_len {
|
||||
max_len = len;
|
||||
ans_pos = pos;
|
||||
|
|
Loading…
Reference in a new issue