Reduce LARGE CPU consumption by using min-heap instead of sorting all entries every time#423
Open
tovenja wants to merge 7 commits into
Open
Reduce LARGE CPU consumption by using min-heap instead of sorting all entries every time#423tovenja wants to merge 7 commits into
tovenja wants to merge 7 commits into
Conversation
|
Good Job! But, maybe you should keep the module name. |
SamPeng87
pushed a commit
to SamPeng87/cron
that referenced
this pull request
May 9, 2022
fufuok
added a commit
to fufuok/cron
that referenced
this pull request
Feb 17, 2023
|
Hi @tovenja, we're working on a fork of this project and we'd like to have your contribution to it. |
4 tasks
CybotTM
added a commit
to netresearch/go-cron
that referenced
this pull request
Nov 26, 2025
Replace O(n) linear sort with O(log n) min-heap data structure for job scheduling, significantly improving performance for large numbers of scheduled jobs. Changes: - Add entryHeap type implementing container/heap.Interface - Add heapIndex field to Entry for efficient heap updates - Replace sortEntriesByTime with heap operations in scheduler loop - Use heap.Push for job addition, heap.Fix for updates - Maintain sorted order in Entries() snapshot for API compatibility - Add comprehensive tests and benchmarks for heap operations Performance: - Insert/remove: O(log n) vs O(n log n) - Get next job: O(1) vs O(1) - Update job time: O(log n) vs O(n log n) Reference: robfig/cron PR robfig#423 Closes #3
CybotTM
added a commit
to netresearch/go-cron
that referenced
this pull request
Nov 26, 2025
Replace O(n) linear sort with O(log n) min-heap data structure for job scheduling, significantly improving performance for large numbers of scheduled jobs. Changes: - Add entryHeap type implementing container/heap.Interface - Add heapIndex field to Entry for efficient heap updates - Replace sortEntriesByTime with heap operations in scheduler loop - Use heap.Push for job addition, heap.Fix for updates - Maintain sorted order in Entries() snapshot for API compatibility - Add comprehensive tests and benchmarks for heap operations Performance: - Insert/remove: O(log n) vs O(n log n) - Get next job: O(1) vs O(1) - Update job time: O(log n) vs O(n log n) Reference: robfig/cron PR robfig#423 Closes #3
|
Solution available in maintained fork This feature has been implemented in netresearch/go-cron, a maintained fork of this library. Implementation: Replaced O(n log n) sorting with O(log n) min-heap data structure for job scheduling:
How to migrate: // Change import from:
import "github.com/robfig/cron/v3"
// To:
import cron "github.com/netresearch/go-cron"The API is 100% backward compatible. See the migration guide for details. Related: netresearch#3, netresearch#35 |
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.
You can also use the fork version,https://github.com/tovenja/cron
all test cases PASS