Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove slice capacity hint in x/sync #1350

Merged
merged 5 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/sync/syncmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ func NewStateSyncManager(config StateSyncConfig) (*StateSyncManager, error) {
m := &StateSyncManager{
config: config,
syncDoneChan: make(chan struct{}),
unprocessedWork: newSyncWorkHeap(2 * config.SimultaneousWorkLimit),
processedWork: newSyncWorkHeap(2 * config.SimultaneousWorkLimit),
unprocessedWork: newSyncWorkHeap(),
processedWork: newSyncWorkHeap(),
}
m.unprocessedWorkCond.L = &m.workLock

Expand Down
4 changes: 2 additions & 2 deletions x/sync/syncworkheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type syncWorkHeap struct {
closed bool
}

func newSyncWorkHeap(maxSize int) *syncWorkHeap {
func newSyncWorkHeap() *syncWorkHeap {
return &syncWorkHeap{
priorityHeap: make([]*heapItem, 0, maxSize),
priorityHeap: make([]*heapItem, 0),
sortedItems: btree.NewG(
2,
func(a, b *heapItem) bool {
Expand Down
12 changes: 6 additions & 6 deletions x/sync/syncworkheap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func Test_SyncWorkHeap_Heap_Methods(t *testing.T) {
require := require.New(t)

h := newSyncWorkHeap(1)
h := newSyncWorkHeap()
require.Equal(0, h.Len())

item1 := &heapItem{
Expand Down Expand Up @@ -92,7 +92,7 @@ func Test_SyncWorkHeap_Heap_Methods(t *testing.T) {
// Tests Insert and GetWork
func Test_SyncWorkHeap_Insert_GetWork(t *testing.T) {
require := require.New(t)
h := newSyncWorkHeap(1)
h := newSyncWorkHeap()

item1 := &syncWorkItem{
start: []byte{0},
Expand Down Expand Up @@ -143,7 +143,7 @@ func Test_SyncWorkHeap_Insert_GetWork(t *testing.T) {
func Test_SyncWorkHeap_remove(t *testing.T) {
require := require.New(t)

h := newSyncWorkHeap(1)
h := newSyncWorkHeap()

item1 := &syncWorkItem{
start: []byte{0},
Expand Down Expand Up @@ -190,7 +190,7 @@ func Test_SyncWorkHeap_remove(t *testing.T) {

func Test_SyncWorkHeap_Merge_Insert(t *testing.T) {
// merge with range before
syncHeap := newSyncWorkHeap(1000)
syncHeap := newSyncWorkHeap()

syncHeap.MergeInsert(&syncWorkItem{start: nil, end: []byte{63}})
require.Equal(t, 1, syncHeap.Len())
Expand All @@ -205,7 +205,7 @@ func Test_SyncWorkHeap_Merge_Insert(t *testing.T) {
require.Equal(t, 3, syncHeap.Len())

// merge with range after
syncHeap = newSyncWorkHeap(1000)
syncHeap = newSyncWorkHeap()

syncHeap.MergeInsert(&syncWorkItem{start: nil, end: []byte{63}})
require.Equal(t, 1, syncHeap.Len())
Expand All @@ -220,7 +220,7 @@ func Test_SyncWorkHeap_Merge_Insert(t *testing.T) {
require.Equal(t, 3, syncHeap.Len())

// merge both sides at the same time
syncHeap = newSyncWorkHeap(1000)
syncHeap = newSyncWorkHeap()

syncHeap.MergeInsert(&syncWorkItem{start: nil, end: []byte{63}})
require.Equal(t, 1, syncHeap.Len())
Expand Down