Skip to content

Commit

Permalink
performance: slight performance improvement when handling modules => …
Browse files Browse the repository at this point in the history
…only sort onces every module is done
  • Loading branch information
abenz1267 committed Aug 16, 2024
1 parent bcd5fd6 commit 79dac2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions internal/modules/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ func (f *Finder) SetupData(cfg *config.Config, ctx context.Context) {

fileWalker.SetErrorHandler(errorHandler)

isWalking := make(chan bool)
done := make(chan bool)

go func(isWalking chan bool) {
err := fileWalker.Start()
if err == nil {
isWalking <- false
}
}(isWalking)
}(done)

for {
select {
case <-isWalking:
case <-done:
fileWalker.Terminate()
f.general.IsSetup = true
f.general.HasInitialSetup = true
Expand Down
16 changes: 0 additions & 16 deletions internal/ui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sync"

"github.com/abenz1267/walker/internal/util"
"github.com/diamondburned/gotk4/pkg/glib/v2"
)

type Handler struct {
Expand All @@ -28,21 +27,6 @@ func (h *Handler) handle() {

h.mut.Lock()
h.entries = append(h.entries, entries...)

if !appstate.KeepSort && !h.keepSort {
sortEntries(h.entries)
}

if len(h.entries) > cfg.List.MaxEntries {
h.entries = h.entries[:cfg.List.MaxEntries]
}

if len(h.entries) > 0 {
glib.IdleAdd(func() {
common.items.Splice(0, int(common.items.NItems()), h.entries...)
})
}

h.mut.Unlock()
case <-h.ctx.Done():
return
Expand Down
18 changes: 18 additions & 0 deletions internal/ui/interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,24 @@ func processAsync(ctx context.Context, text string) {

wg.Wait()

handler.mut.Lock()

if !appstate.KeepSort && !handler.keepSort {
sortEntries(handler.entries)
}

if len(handler.entries) > cfg.List.MaxEntries {
handler.entries = handler.entries[:cfg.List.MaxEntries]
}

if len(handler.entries) > 0 {
glib.IdleAdd(func() {
common.items.Splice(0, int(common.items.NItems()), handler.entries...)
})
}

handler.mut.Unlock()

if !layout.Window.Box.Search.Spinner.Hide {
elements.spinner.SetVisible(false)
}
Expand Down

0 comments on commit 79dac2b

Please sign in to comment.