Skip to content

Commit 5169eeb

Browse files
authored
merge: pull request #1 from bitswired/feat/cb_channels
feat: use cross beam channels avoid lock and arc
2 parents 6dd0897 + 2e891e4 commit 5169eeb

4 files changed

Lines changed: 28 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kiru-core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# kiru/Cargo.toml
22
[package]
33
name = "kiru"
4-
version = "0.1.9"
4+
version = "0.1.10"
55
edition = "2021"
66
description = "Fast text chunking for Rust"
77
license = "MIT"
@@ -25,6 +25,7 @@ glob = { workspace = true }
2525
rayon = { workspace = true }
2626
serde = { workspace = true }
2727
serde_json = { workspace = true }
28+
crossbeam-channel = "0.5.15"
2829

2930
[dev-dependencies]
3031
tempfile = { workspace = true }

kiru-core/src/chunker.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use crossbeam_channel::bounded;
12
use glob::glob;
23
use rayon::prelude::*;
3-
use std::sync::{mpsc, Mutex};
4+
use std::io;
45
use std::thread;
5-
use std::{io, sync::Arc};
66
use thiserror::Error;
77

88
use crate::{BytesChunker, CharactersChunker, StreamType};
@@ -249,9 +249,8 @@ impl ChunkerWithStrategy {
249249
StreamType::from_source(source)?; // This validates the source
250250
}
251251

252-
let (sender, receiver) = mpsc::sync_channel(channel_size);
252+
let (sender, receiver) = bounded(channel_size);
253253
let chunker_params = self.chunker_params.clone();
254-
let receiver: Arc<Mutex<mpsc::Receiver<String>>> = Arc::new(Mutex::new(receiver));
255254

256255
thread::spawn({
257256
move || {
@@ -273,13 +272,7 @@ impl ChunkerWithStrategy {
273272
}
274273
});
275274

276-
let iterator = std::iter::from_fn({
277-
let receiver: Arc<Mutex<mpsc::Receiver<String>>> = Arc::clone(&receiver); // Clone Arc for iterator
278-
move || {
279-
let receiver = receiver.lock().unwrap();
280-
receiver.recv().ok()
281-
}
282-
});
275+
let iterator = std::iter::from_fn(move || receiver.recv().ok());
283276

284277
Ok(Box::new(iterator))
285278
}

kiru-py/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# kiru-py/Cargo.toml
22
[package]
33
name = "kiru-py"
4-
version = "0.1.9"
4+
version = "0.1.10"
55
edition = "2021"
66
description = "Python bindings for kiru text chunking library"
77
repository = "https://github.com/bitswired/kiru"
@@ -17,6 +17,6 @@ pyo3 = { workspace = true }
1717

1818
[dependencies.kiru]
1919
path = "../kiru-core"
20-
version = "0.1.9"
20+
version = "0.1.10"
2121
[build-dependencies]
2222
# None needed for simple bindings

0 commit comments

Comments
 (0)