Merged
Conversation
A Queue[T comparable] implementation where each element becomes dequeuable at a deadline computed by a caller-supplied function at Offer time. API: - NewDelay(elems, deadlineFunc, opts...) — matches NewPriority's constructor-time func pattern. - Queue[T] surface plus GetWait. - MarshalJSON serialises in deadline order. Impl: - Min-heap by deadline, written directly on []delayed[T] rather than via container/heap. The container/heap Push/Pop signatures require boxing each element into `any`, which pprof showed as the dominant allocation source (>75% of allocations, ~50% of CPU spent in GC). Typed push/pop/up/down keeps Get+Offer steady-state at 0 allocs. - GetWait uses sync.Cond + time.AfterFunc so "head is due" and "state changed" compose under a single Wait, matching the cond-var idiom used by Blocking. - Peek returns the head regardless of whether its deadline has passed (matches java.util.concurrent.DelayQueue.peek). - Panics on nil deadlineFunc or negative capacity, consistent with NewPriority. README: new Delay Queue section with usage example; benchmark table extended.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 5 6 +1
Lines 483 639 +156
==========================================
+ Hits 483 639 +156
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
New
Delay[T comparable]queue where each element becomes dequeuable at a deadline computed by a caller-supplied function atOffertime. Satisfies the existingQueue[T]interface — no separate interface introduced.API
Implementation notes
[]delayed[T]rather than viacontainer/heap. pprof on theGet_Offerbenchmark showed container/heap'sanyboxing accounted for >75% of allocations and ~50% of CPU in GC. Typedpush/pop/up/downkeep the steady-state offer-then-get loop at 0 allocs.GetWaitusessync.Cond+time.AfterFuncso "head is due" and "state changed" compose under a singleWait, matching the cond-var idiom used byBlocking.Peekreturns the head regardless of whether its deadline has passed — matchesjava.util.concurrent.DelayQueue.peek.deadlineFuncor negative capacity, consistent withNewPriority.Benchmarks
(
B/oponOfferis amortized slice growth from unbounded pushes in the benchmark; no per-op alloc.)Test plan
go test -race -shuffle=on .go test -coverprofile— 100% statementsgolangci-lint runpasses locally