Skip to content

SPSCReceiverStream BufferPool allocator#21

Merged
blogle merged 7 commits intomasterfrom
buf_proto
Aug 5, 2025
Merged

SPSCReceiverStream BufferPool allocator#21
blogle merged 7 commits intomasterfrom
buf_proto

Conversation

@blogle
Copy link
Copy Markdown
Owner

@blogle blogle commented Aug 4, 2025

This PR replaces the BorrowedSlice that was previously returned from the SPSCReceiverStream with a memoryview from a BufferPool. The previous implementation had the limitation that each borrow was invalidated on the subsequent call to anext. This prevented the stream from being used with combinators like chunks/ready_chunks.

Additionally the rest of the api was updated to yield bytearrays instead of bytes objects, this makes it possible to build arrays/tensors in libraries that expect a mutable buffer object.

blogle and others added 7 commits August 4, 2025 16:20
- Simplify SPSCReceiver.recv() to return bytearray copies for straightforward usage
- Dramatically simplify ManagedBuffer class to only include view() method and essential functionality
- Keep buffer pool optimization focused on streaming scenarios where it provides most value
- Add comprehensive SPSC buffer implementation specification (spsc_buf_impl.md)
- Create internal buffer module (kioto/internal/buffer.py) with BufferPool and ManagedBuffer
- Update tests to reflect simplified API and remove unused method tests
- Achieve clean separation: simple copy semantics for recv(), zero-copy optimization for streaming
- Reduce ManagedBuffer complexity by ~60% while maintaining all actual functionality
- Move SlotQueue, _PutSlot, and _GetSlot classes from kioto/streams/impl.py to kioto/internal/buffer.py
- Update imports in streams implementation to use internal module
- Consolidate internal infrastructure components in single module
- Maintain all existing functionality and API compatibility
- All 126 tests continue to pass with no regressions
- Create kioto/internal/queue.py for async queue utilities
- Move SlotQueue and helper classes from buffer.py to queue.py for proper separation of concerns
- Update streams/impl.py import to use queue module instead of buffer module
- Buffer module now exclusively contains buffer pool and managed buffer classes
- Queue module now exclusively contains async queue implementations
- All 126 tests continue to pass with proper module organization
- Replace 'assert b"test" in owned or b"data" in owned' with 'assert owned == b"test data"'
- Replace 'assert chunk_bytes[0] in [ord("h"), ord(" ")]' with 'assert chunk_bytes == b"hello wo"'
- Replace 'assert b"persistent" in all_data or b"data" in all_data' with 'assert all_data == b"persistentdata"'
- Remove non-deterministic 'or' conditions from test assertions
- Use exact expected values based on deterministic buffer chunking behavior
- All 126 tests continue to pass with more precise verification
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 4, 2025

Codecov Report

❌ Patch coverage is 90.65421% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.36%. Comparing base (7ecac80) to head (0d0fa23).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
kioto/internal/buffer.py 84.21% 2 Missing and 4 partials ⚠️
kioto/channels/impl.py 86.66% 1 Missing and 1 partial ⚠️
kioto/internal/queue.py 98.00% 0 Missing and 1 partial ⚠️
kioto/streams/impl.py 75.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
- Coverage   87.55%   87.36%   -0.20%     
==========================================
  Files          20       22       +2     
  Lines        1278     1266      -12     
  Branches      158      160       +2     
==========================================
- Hits         1119     1106      -13     
+ Misses        109      108       -1     
- Partials       50       52       +2     
Files with missing lines Coverage Δ
kioto/internal/queue.py 98.00% <98.00%> (ø)
kioto/streams/impl.py 96.23% <75.00%> (-0.24%) ⬇️
kioto/channels/impl.py 86.25% <86.66%> (-0.43%) ⬇️
kioto/internal/buffer.py 84.21% <84.21%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@blogle blogle merged commit 74982da into master Aug 5, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant