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

fix: slightly reduce memory usage when walking large directory trees #45

Merged
merged 1 commit into from
Aug 1, 2019
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
18 changes: 9 additions & 9 deletions merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
depth int
}

feed := make(chan *cidDepth)
out := make(chan *linksDepth)
feed := make(chan cidDepth)
out := make(chan linksDepth)
done := make(chan struct{})

var visitlk sync.Mutex
Expand Down Expand Up @@ -505,7 +505,7 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
return
}

outLinks := &linksDepth{
outLinks := linksDepth{
links: links,
depth: depth + 1,
}
Expand All @@ -526,10 +526,10 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
defer close(feed)

send := feed
var todoQueue []*cidDepth
var todoQueue []cidDepth
var inProgress int

next := &cidDepth{
next := cidDepth{
cid: root,
depth: 0,
}
Expand All @@ -542,22 +542,22 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
next = todoQueue[0]
todoQueue = todoQueue[1:]
} else {
next = nil
next = cidDepth{}
send = nil
}
case <-done:
inProgress--
if inProgress == 0 && next == nil {
if inProgress == 0 && !next.cid.Defined() {
return nil
}
case linksDepth := <-out:
for _, lnk := range linksDepth.links {
cd := &cidDepth{
cd := cidDepth{
cid: lnk.Cid,
depth: linksDepth.depth,
}

if next == nil {
if !next.cid.Defined() {
next = cd
send = feed
} else {
Expand Down