Add trim lifecycle observability, statistics tracking, and allocation sizing#30
Merged
bernardladenthin merged 1 commit intomasterfrom Apr 15, 2026
Merged
Conversation
…im signals Add documentation for all new public API introduced since fcf9f0a (merged in PR #29): - Statistics Tracking: getTotalBytesWritten, getTotalBytesRead, getMaxObservedBytes with note that internal trim I/O is excluded from counts - Configurable Trim Allocation Size: setMaxAllocationSize / getMaxAllocationSize, including default value, IllegalArgumentException contract, and smart-skip logic - Trim Observer Signals: addTrimStartSignal / addTrimEndSignal (and remove variants) with code example showing the semaphore lifecycle pattern - isTrimRunning() getter and getBufferElementCount() getter in API table - Extended Thread Safety volatile-fields list with all new volatile state - Updated Buffer Trimming section with maxAllocationSize, isTrimRunning, and the smart-skip edge-case explanation - Extended Signal/Slot section with forward reference to Trim Observer Signals - Updated Testing section: JUnit 4 → JUnit 5 and added new test coverage bullets https://claude.ai/code/session_015f5tWNnFyhBYoyZAt3EC8i
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances
StreamBufferwith comprehensive observability and control features for the trim operation, adds cumulative I/O statistics tracking, and introduces configurable allocation sizing for trim consolidation. The changes improve visibility into buffer behavior and provide fine-grained control over memory consolidation.Key Changes
Trim Lifecycle Signals: Added
addTrimStartSignal(),removeTrimStartSignal(),addTrimEndSignal(), andremoveTrimEndSignal()methods to observe when trim cycles begin and complete. Uses the same semaphore-based notification pattern as general modification signals.Statistics Tracking: Introduced three new volatile fields to track cumulative I/O:
getTotalBytesWritten()— cumulative bytes written by user operations (excludes internal trim)getTotalBytesRead()— cumulative bytes consumed by user reads (excludes internal trim)getMaxObservedBytes()— peak value of buffered bytes ever observedConfigurable Trim Allocation Size: Added
setMaxAllocationSize(long)andgetMaxAllocationSize()to limit the size of individual byte arrays produced during trim consolidation. WhenavailableBytes > maxAllocationSize, trim produces multiple smaller chunks instead of one large array.Trim Execution Observability: Added
isTrimRunning()volatile method to check whether a trim cycle is currently executing.Smart Trim Skipping: Trim now automatically skips consolidation when the resulting chunk count would not be smaller than the current deque size, preventing repeated no-op trims when
maxAllocationSizeis very small.Enhanced API Reference: Updated documentation with new methods, clarified that
getBufferSize()is legacy, and addedgetBufferElementCount()as the synchronized alternative.Test Framework Update: Updated test documentation to reflect migration from JUnit 4 with
DataProviderRunnerto JUnit 5 (JUnit Jupiter).Implementation Details
maxAllocationSize,isTrimRunning,maxObservedBytes,totalBytesWritten,totalBytesReadCopyOnWriteArrayListinstances for thread-safe concurrent accessisTrimRunningbefore updating to ensure only user I/O is countedhttps://claude.ai/code/session_015f5tWNnFyhBYoyZAt3EC8i