[shell-operator] feat/compaction and queue refactor#789
Merged
Conversation
c078c70 to
b5981c4
Compare
d0c2e10 to
8954380
Compare
8954380 to
9f1f634
Compare
ldmonster
reviewed
Aug 5, 2025
ldmonster
reviewed
Aug 5, 2025
ldmonster
reviewed
Aug 5, 2025
ldmonster
reviewed
Aug 5, 2025
f050f1e to
621d369
Compare
ed45f2d to
5ae5623
Compare
kvm999
reviewed
Aug 7, 2025
kvm999
reviewed
Aug 7, 2025
5ae5623 to
8df720f
Compare
Signed-off-by: Timur Tuktamyshev <timur.tuktamyshev@flant.com>
8df720f to
f2d370c
Compare
Signed-off-by: Timur Tuktamyshev <timur.tuktamyshev@flant.com>
ldmonster
approved these changes
Aug 8, 2025
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.
Overview
This PR introduces a new linked list-based task queue implementation (
TaskQueue) alongside the existing slice-based implementation (TaskQueueSlice). The new implementation provides consistent O(1) performance for all queue operations and includes a newcompactionfunction that intelligently merges HookRun tasks for the same hook, significantly reducing queue size and improving processing efficiency.What this PR does / why we need it
Problem Statement:
The current slice-based queue implementation (
TaskQueueSlice) suffers from catastrophic performance degradation for certain operations:AddFirst: O(n) complexity causing 160-200x slowdown compared to linked listGetByID: O(n) complexity with 6-53x performance degradation as queue size growsSolution:
This PR introduces a new
TaskQueueimplementation based on Go'scontainer/listwith the following improvements:Key Features:
compactionmethod for intelligent task mergingcompactionMethod:This PR introduces a brand new
compactionmethod that addresses a critical gap in the existing queue implementation. This method intelligently merges HookRun tasks for the same hook, significantly reducing queue size and improving processing efficiency.Why Compaction is Essential:
Compaction Algorithm Features:
Compaction Process:
Performance Improvements (benchmark results on Apple M3):
Compaction-Specific Benefits:
Trade-offs:
AddLastis 1.6x slower (513 ns vs 313 ns) but remains in microsecond rangeWhy this matters:
Implementation Details:
container/listfor O(1) list operationsidIndexmap for O(1) task lookupcompactionwith sophisticated merging logicMigration Path:
The existing
TaskQueueSliceimplementation is preserved mainly for testing and benchmarkingIf we add compaction to the slice-based implementation
For completeness, I have also implemented the same
compactionlogic for the slice-based queue. This allows for a direct, apples-to-apples comparison of compaction performance and memory usage between the two data structures.Benchmark results for compaction (Apple M3, Go 1.24.0):
Key takeaways:
Why this matters:
If you expect your queue to grow large or require frequent compaction (e.g., in high-throughput or long-running systems), the linked list implementation will provide much more predictable and efficient performance, both in terms of speed and memory usage.
Special notes for your reviewer
Performance Considerations:
Backward Compatibility:
TaskQueueSliceremains functionalBenchmark Environment: