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

go-fuzz-build: parallelize build #172

Closed
wants to merge 892 commits into from
Closed

Conversation

josselin-c
Copy link

Parallelize some build steps to improve build speed.
On my particular test on a macosx system, the build time goes from 2m05
to 1m17.

taotetek and others added 23 commits February 16, 2017 06:59
trophies: add github.com/digitalocean/captainslog
Update to the current location of the freetype library
Currently we have hardcoded list of go-fuzz-dep dependencies.
This list constantly changes due to changes in std lib
(due various new internal packages).
Extract go-fuzz-dep dependencies automatically with 'go list'.

Fixes dvyukov#157
Update list of trophies in README file
Add two trophies to README file
fixes build error in png example, g1.9
Add github.com/spenczar/tdigest trophies
…er library.

Specifically:
* Fixed the issues related to API changes.
* Changed to using the ParseNext() API (which can parse multiple statements).
* Changed to use the io.Reader interface.
* Added a class to artificially reduce the chunks that can be read, to increase the chance of buffer underrun/overrun errors.
Updated the sqlparser fuzzer to use the latest version of the library.
Parallelize some build steps to improve build speed.
On my particular test on a macosx system, the build time goes from 2m05
to 1m17.
wg.Add(1)
sem <- true
go func(p string) {
res := goListBool(p, "Standard")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If go list invocation is the problem, then we should extract all interesting properties and once. Currently we run go list 4 times per-package: to check Standart, extract Import, GoFiles CgoFiles.

@@ -194,9 +213,20 @@ func buildInstrumentedBinary(pkg string, deps map[string]bool, lits map[Literal]
// Cross-compilation is not implemented.
copyDir(filepath.Join(GOROOT, "pkg", runtime.GOOS+"_"+runtime.GOARCH), filepath.Join(workdir, "goroot", "pkg", runtime.GOOS+"_"+runtime.GOARCH), true, nil)
}

wg := sync.WaitGroup{}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var wg sync.WaitGroup please as more standard.
In one codebase I counted 2598 uses of var wg sync.WaitGroup vs 1 for wg := sync.WaitGroup{}.

defer wg.Done()
defer func() { <-sem }()

impList := goListList(pkg, "Imports")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we only parallelize go list, right? So if we call go list once to extract all properties, this part will go away.

@@ -362,7 +407,11 @@ func instrumentPackages(workdir string, deps map[string]bool, lits map[Literal]s
}
path := filepath.Join(workdir, root, "src", p.name)
var files []*ast.File
for _, fn := range append(goListList(p.name, "GoFiles"), goListList(p.name, "CgoFiles")...) {
xgoFiles := make(chan []string, 2)
go func() { xgoFiles <- goListList(p.name, "GoFiles") }()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also go away if we call go list once.

@@ -71,10 +75,25 @@ func main() {
}

deps := make(map[string]bool)
mu := sync.Mutex{}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, var my sync.Mutex.

@josselin-c
Copy link
Author

Thanks for your feedback. I'll try to find some free time to improve on this.

@AlekSi
Copy link
Contributor

AlekSi commented Feb 6, 2018

@josselin-c Please note that go-fuzz repository history was rewritten to reduce total repository size and download time. The easiest migration path for this PR is to git cherry-pick commits on top of current master.

@josharian
Copy link
Collaborator

#211 substantively changed go-fuzz-build, making it faster in the process. I can imagine that you don't want to revisit this, but it might be interesting to look at the new go-fuzz-build, and see whether your optimizations still apply.

@josharian
Copy link
Collaborator

I looked through the relevant commit, and found that all but one of the improvements have been incorporated into go-fuzz, by way of using go/packages. The outstanding one is parallelizing package cloning. In my experiments, that is not a significant build time factor. So I'm going to close this PR. Thanks again for taking the time to work on it.

@josharian josharian closed this Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.