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

Improve performance with large numbers of untracked or modified files #3919

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
22 changes: 17 additions & 5 deletions pkg/gui/filetree/build_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
func BuildTreeFromFiles(files []*models.File) *Node[models.File] {
root := &Node[models.File]{}

childrenMapsByNode := make(map[*Node[models.File]]map[string]*Node[models.File])

var curr *Node[models.File]
for _, file := range files {
splitPath := split(file.Name)
Expand All @@ -23,11 +25,19 @@ func BuildTreeFromFiles(files []*models.File) *Node[models.File] {
}

path := join(splitPath[:i+1])
for _, existingChild := range curr.Children {
if existingChild.Path == path {
curr = existingChild
continue outer
}

var currNodeChildrenMap map[string]*Node[models.File]
var isCurrNodeMapped bool

if currNodeChildrenMap, isCurrNodeMapped = childrenMapsByNode[curr]; !isCurrNodeMapped {
currNodeChildrenMap = make(map[string]*Node[models.File])
childrenMapsByNode[curr] = currNodeChildrenMap
}

child, doesCurrNodeHaveChildAlready := currNodeChildrenMap[path]
if doesCurrNodeHaveChildAlready {
curr = child
continue outer
}

newChild := &Node[models.File]{
Expand All @@ -36,6 +46,8 @@ func BuildTreeFromFiles(files []*models.File) *Node[models.File] {
}
curr.Children = append(curr.Children, newChild)

currNodeChildrenMap[path] = newChild

curr = newChild
}
}
Expand Down
Loading