Closed
perf: hot-path optimizations for enqueue!, poll!, and ack!#1
Conversation
Copilot created this pull request from a session on behalf of
mpenet
April 13, 2026 07:13
View session
mpenet
marked this pull request as ready for review
April 13, 2026 07:14
- Item 1: Segment pre-creation with 75% fill threshold - Item 2: Branchless alignment in aligned-frame-size - Item 3: Binary search in find-segment-for-offset - Item 4: Cache current segment in volatile field on Queue - Item 5: Use ByteBuffer.slice(index, length) in try-read-one! - Item 6: Fused lrbFrontier method on ILongRingBuffer - Item 7: Volatile boolean for cursor-dirty instead of atom fix: address code review feedback - fix pre-creation base-offset, use integer threshold, clearer binary search - Fix critical bug: pre-create segment with temp file + atomic rename instead of wrong base-offset. Pre-created segment now always usable at roll time. - Replace float division threshold with integer arithmetic (capacity - capacity/4) - Use bit-shift-right instead of unsigned-bit-shift-right in binary search - Remove unused segment-precreate-fill-ratio constant Agent-Logs-Url: https://github.com/mpenet/k7/sessions/cb0fbabb-c116-4070-bd98-89de2903848d Co-authored-by: mpenet <106390+mpenet@users.noreply.github.com> refactor: extract atomic-move-opts constant to avoid per-roll allocation Agent-Logs-Url: https://github.com/mpenet/k7/sessions/cb0fbabb-c116-4070-bd98-89de2903848d Co-authored-by: mpenet <106390+mpenet@users.noreply.github.com>
mpenet
force-pushed
the
copilot/implement-feature-1-2-3-4-5a-6-7
branch
from
April 13, 2026 07:18
3007e89 to
d93c0c1
Compare
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.
Implements items 1–7 from the performance improvement plan targeting the enqueue/poll/ack hot paths.
Changes
if (zero? r)with(bit-and (+ total frame-align-mask) (bit-not frame-align-mask))find-segment-for-offsetuses binary search instead of linear scan over the sorted segments vectorQueuegains a^:volatile-mutable ^Segment current-segfield, eliminating(peek @segments)atom deref + vector peek on everyenqueue!/poll!ByteBuffer.slice(index, length)—try-read-one!uses the 2-arg slice (Java 13+), dropping the.duplicate+ position/limit dance (one fewer allocation per message)lrbFrontier— singlelrbFrontier(read-head)interface method replaceslrb-empty?+lrb-firsttwo-dispatch sequence inack!cursor-dirty—^:volatile-mutable ^boolean cursor-dirtyreplaces theatom(AtomicReference CAS) on every async ackroll-segment!does an atomic rename and wraps the existing resources, avoiding file allocation/mmap latency on the roll-triggering writePre-creation design
All 30 existing tests pass unchanged.