Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Commit 1b5f715

Browse files
committed
feat: update ConcurrentBuffer and ConcurrentQueue for improved performance and add usage guidelines
1 parent 5680838 commit 1b5f715

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ High-performance **thread-safe** (No-GIL–friendly) data structures and paralle
2222

2323
## 🚀 Features
2424

25-
26-
2725
## Concurrent Data Structures
2826
### 1. ConcurrentBag
2927
- A thread-safe “multiset” collection that allows duplicates.
@@ -51,6 +49,15 @@ High-performance **thread-safe** (No-GIL–friendly) data structures and paralle
5149
- Ideal for last-in, first-out (LIFO) workloads.
5250
- Built on `deque` for fast appends and pops.
5351

52+
### 6. ConcurrentBuffer
53+
- A **high-performance**, thread-safe buffer using **sharded deques** for low-contention access.
54+
- Designed to handle massive producer/consumer loads with better throughput than standard queues.
55+
- Supports `enqueue`, `dequeue`, `peek`, `clear`, and bulk operations (`map`, `filter`, `reduce`).
56+
- **Timestamp-based ordering** ensures approximate FIFO behavior across shards.
57+
- Outperforms `ConcurrentQueue` by up to **60%** in mid-range concurrency (4–20 threads).
58+
- Automatically balances items across shards; ideal for parallel pipelines and low-latency workloads.
59+
- Best used with `shard_count ≈ thread_count / 2` for optimal performance.
60+
5461

5562
## Parallel Operations
5663
### 1. Parallel Utilities (TPL-like)

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ classifiers = [
4747
"Topic :: System :: Networking",
4848
"Topic :: Utilities",
4949
"Environment :: Console",
50-
"License :: OSI Approved :: MIT License"
5150
]
5251

5352
dependencies = []

src/thread_factory/concurrency/concurrent_buffer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import functools
2-
import random
32
import threading
43
import time
54
from collections import deque
@@ -422,7 +421,7 @@ def remove_item(self, item: _T) -> bool:
422421

423422
def reduce(self, func: Callable[[Any, _T], Any], initial: Optional[Any] = None) -> Any:
424423
"""
425-
Applies a function of two arguments cumulatively to the items of the buffer, from left to right, so as to reduce the buffer to a single value.
424+
Applies a function of two arguments cumulatively to the items of the buffer, from left to right, to reduce the buffer to a single value.
426425
427426
Args:
428427
func (Callable[[Any, _T], Any]): The function to apply.

0 commit comments

Comments
 (0)