Skip to content

Commit 3fabb2c

Browse files
committed
rm the deprecated batch APIs
1 parent d89055e commit 3fabb2c

File tree

14 files changed

+30
-163
lines changed

14 files changed

+30
-163
lines changed

CHANGELOG.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,13 @@ These vector-like types heavily depended on reliable length tracking for indexin
132132
- **Expected improvement**: 10-100x faster prefix allocation under contention
133133

134134
**4. WriteBatch API for Bulk Operations**
135-
- New `RocksEngine::write_batch()` method for atomic batch writes
136-
- Leverages RocksDB's native WriteBatch for optimal performance
137-
- Reduces per-operation overhead and improves throughput
138-
- **Use case**: Bulk inserts, transaction-like operations
135+
- New `Mapx::batch_entry()` method for atomic batch writes
136+
- Removed `Mapx::batch()` closure-based API
139137

140-
```rust
141138
// Example: Batch write
142-
engine.write_batch(prefix, |batch| {
143-
for i in 0..1000 {
144-
batch.insert(&key(i), &value(i));
145-
}
146-
});
147-
```
139+
let mut batch = engine.batch_entry();
140+
batch.insert(&key(i), &value(i));
141+
batch.commit().unwrap();
148142

149143
**Performance Impact:**
150144
- **Single writes**: 5-15% faster due to reduced allocations

OPTIMIZATION_SUMMARY.md

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,18 @@ fn set_max_key_len(&self, len: usize) {
8080

8181
```rust
8282
/// Batch write operations for better performance
83-
pub fn write_batch<F>(&self, meta_prefix: PreBytes, f: F)
84-
where
85-
F: FnOnce(&mut dyn BatchTrait)
86-
{
87-
let db = self.get_db(meta_prefix);
88-
let cf = self.get_cf(meta_prefix);
89-
let mut batch = RocksBatch::new(meta_prefix, cf);
90-
f(&mut batch);
91-
db.write(batch.inner).unwrap();
92-
93-
// ... update max_keylen logic
94-
}
83+
let mut batch = map.batch_entry();
84+
batch.insert(&key, &value);
85+
batch.commit().unwrap();
9586
```
9687

9788
**Usage Example**:
9889

9990
```rust
100-
map.batch(|batch| {
101-
for i in 0..1000 {
102-
batch.insert(&key(i), &value(i));
103-
}
104-
});
91+
// Example: Batch write
92+
let mut batch = map.batch_entry();
93+
batch.insert(&key(i), &value(i));
94+
batch.commit().unwrap();
10595
```
10696

10797
**Effect**:
@@ -148,7 +138,7 @@ fn alloc_prefix(&self) -> Pre {
148138
| Operation Type | Before | After | Improvement Source |
149139
| :--- | :--- | :--- | :--- |
150140
| Single Write | Baseline | 5-15% faster | Memory allocation optimization |
151-
| Batch Write | Baseline | 2-5x faster | WriteBatch API |
141+
| Batch Write | Baseline | 2-5x faster | batch_entry API |
152142
| Prefix Allocation (High Concurrency) | Baseline | 10-100x faster | Lock-free algorithm |
153143

154144
## 2. Benchmark Improvements
@@ -270,7 +260,7 @@ Suggested additions:
270260
This optimization work focused on:
271261

272262
1. **RocksDB Engine Core Optimization** - Reduced memory allocation, lower write amplification, improved concurrency performance.
273-
2. **API Improvements** - Added `WriteBatch` support for batch operations.
263+
2. **API Improvements** - Added `batch_entry` support for batch operations.
274264
3. **Code Cleanup** - Removed deprecated `Vecx` related code.
275265
4. **Test Improvements** - Added new performance test cases.
276266

core/src/basic/mapx_raw/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,6 @@ impl MapxRaw {
310310
self.inner.remove(key.as_ref())
311311
}
312312

313-
/// Batch write operations for better performance and atomicity.
314-
///
315-
/// # Arguments
316-
///
317-
/// * `f` - A closure that takes a `&mut BatchTrait` and performs batch operations.
318-
#[inline(always)]
319-
pub fn batch<F>(&mut self, f: F)
320-
where
321-
F: FnOnce(&mut dyn crate::common::BatchTrait),
322-
{
323-
self.inner.write_batch(f);
324-
}
325-
326313
/// Start a batch operation.
327314
///
328315
/// This method allows you to perform multiple insert/remove operations

core/src/basic/mapx_raw/test.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,30 @@ fn test_batch() {
7474
let mut hdr = MapxRaw::new();
7575
let max = 100u64;
7676

77-
hdr.batch(|batch| {
77+
{
78+
let mut batch = hdr.batch_entry();
7879
for i in 0..max {
7980
let key = to_bytes(i);
8081
let value = to_bytes(max + i);
8182
batch.insert(&key, &value);
8283
}
83-
});
84+
batch.commit().unwrap();
85+
}
8486

8587
for i in 0..max {
8688
let key = to_bytes(i);
8789
let value = to_bytes(max + i);
8890
assert_eq!(&pnk!(hdr.get(&key))[..], &value[..]);
8991
}
9092

91-
hdr.batch(|batch| {
93+
{
94+
let mut batch = hdr.batch_entry();
9295
for i in 0..max {
9396
let key = to_bytes(i);
9497
batch.remove(&key);
9598
}
96-
});
99+
batch.commit().unwrap();
100+
}
97101

98102
for i in 0..max {
99103
let key = to_bytes(i);

core/src/common/engines/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ pub trait Engine: Sized {
7070
/// Remove a key. Does not return the old value for performance.
7171
fn remove(&self, meta_prefix: PreBytes, key: &[u8]);
7272

73-
/// Batch write operations.
74-
fn write_batch<F>(&self, meta_prefix: PreBytes, f: F)
75-
where
76-
F: FnOnce(&mut dyn BatchTrait);
77-
7873
/// Alloc a batch.
7974
fn batch_begin<'a>(&'a self, meta_prefix: PreBytes) -> Box<dyn BatchTrait + 'a>;
8075
}
@@ -250,15 +245,6 @@ impl Mapx {
250245
VSDB.db.remove(prefix, key);
251246
}
252247

253-
#[inline(always)]
254-
pub(crate) fn write_batch<F>(&mut self, f: F)
255-
where
256-
F: FnOnce(&mut dyn BatchTrait),
257-
{
258-
let prefix = self.prefix.hack_bytes();
259-
VSDB.db.write_batch(prefix, f);
260-
}
261-
262248
#[inline(always)]
263249
pub(crate) fn batch_begin(&mut self) -> Box<dyn BatchTrait + '_> {
264250
let prefix = self.prefix.hack_bytes();

core/src/common/engines/parity_backend.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,6 @@ impl Engine for ParityEngine {
330330
db.commit([(area_idx as u8, full_key, None)]).unwrap();
331331
}
332332

333-
fn write_batch<F>(&self, meta_prefix: PreBytes, f: F)
334-
where
335-
F: FnOnce(&mut dyn BatchTrait),
336-
{
337-
let mut batch = ParityBatch::new(meta_prefix, self);
338-
f(&mut batch);
339-
batch.commit().unwrap();
340-
}
341-
342333
fn batch_begin<'a>(&'a self, meta_prefix: PreBytes) -> Box<dyn BatchTrait + 'a> {
343334
Box::new(ParityBatch::new(meta_prefix, self))
344335
}

core/src/common/engines/rocks_backend.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,6 @@ impl Engine for RocksEngine {
326326
db.delete_cf(cf, full_key).unwrap();
327327
}
328328

329-
fn write_batch<F>(&self, meta_prefix: PreBytes, f: F)
330-
where
331-
F: FnOnce(&mut dyn BatchTrait),
332-
{
333-
let cf = self.get_cf(meta_prefix);
334-
let mut batch = RocksBatch::new(meta_prefix, cf, self);
335-
f(&mut batch);
336-
batch.commit().unwrap();
337-
}
338-
339329
fn batch_begin<'a>(&'a self, meta_prefix: PreBytes) -> Box<dyn BatchTrait + 'a> {
340330
let cf = self.get_cf(meta_prefix);
341331
Box::new(RocksBatch::new(meta_prefix, cf, self))

wrappers/benches/units/basic_mapx.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ fn read_write(c: &mut Criterion) {
3131

3232
group.bench_function(" batch write (100 items) ", |b| {
3333
b.iter(|| {
34-
db.batch(|batch| {
35-
for _ in 0..100 {
36-
let n = i.fetch_add(1, Ordering::SeqCst);
37-
batch.insert(&[n; 2], &vec![n; 128]);
38-
}
39-
});
34+
let mut batch = db.batch_entry();
35+
for _ in 0..100 {
36+
let n = i.fetch_add(1, Ordering::SeqCst);
37+
batch.insert(&[n; 2], &vec![n; 128]);
38+
}
39+
batch.commit().unwrap();
4040
})
4141
});
4242

wrappers/benches/units/batch_vs_normal.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,7 @@ fn batch_vs_normal_write(c: &mut Criterion) {
2424
})
2525
});
2626

27-
// Case 2: Batch write 100 items (closure)
28-
group.bench_function(" batch closure 100 ", |b| {
29-
b.iter(|| {
30-
db.batch(|batch| {
31-
for _ in 0..100 {
32-
let n = i.fetch_add(1, Ordering::Relaxed);
33-
batch.insert(&n, &n);
34-
}
35-
});
36-
})
37-
});
38-
39-
// Case 3: Batch write 100 items (entry struct)
27+
// Case 2: Batch write 100 items (entry struct)
4028
group.bench_function(" batch entry 100 ", |b| {
4129
b.iter(|| {
4230
let mut batch = db.batch_entry();

wrappers/src/basic/mapx/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,6 @@ where
161161
self.inner.remove(key.encode())
162162
}
163163

164-
/// Batch write operations.
165-
#[inline(always)]
166-
pub fn batch<F>(&mut self, f: F)
167-
where
168-
F: FnOnce(&mut MapxBatch<K, V>),
169-
{
170-
self.inner.batch(|raw_batch| {
171-
let mut batch = MapxBatch {
172-
inner: raw_batch,
173-
_marker: PhantomData,
174-
};
175-
f(&mut batch);
176-
});
177-
}
178-
179164
/// Start a batch operation.
180165
///
181166
/// This method allows you to perform multiple insert/remove operations

0 commit comments

Comments
 (0)