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

Makefile: run generators in parallel #4088

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevekuznetsov
Copy link
Contributor

I don't know necessarily what the benefits are for the built-in Go generation stanzas, but go generate runs everything without parallelism, which makes the make generate target very slow. We can hack around this without asking anyone to stop using Go generate markers by finding packages we need to generate and running them individually. As long as the output is independent, this is safe.

Before:

$ time make generate
(re)installing /home/stevekuznetsov/go/bin/bingo-v0.9.0
/home/stevekuznetsov/go/bin/bingo-v0.9.0 get -l
go generate ./...
bindata.go
bindata.go
make imports
make[1]: Entering directory '/home/stevekuznetsov/code/Azure/ARO-RP/src/github.com/Azure/ARO-RP'
(re)installing /home/stevekuznetsov/go/bin/openshift-goimports-v0.0.0-20230304234052-c70783e636f2
/home/stevekuznetsov/go/bin/openshift-goimports-v0.0.0-20230304234052-c70783e636f2 --module github.com/Azure/ARO-RP
// ...
make[1]: Leaving directory '/home/stevekuznetsov/code/Azure/ARO-RP/src/github.com/Azure/ARO-RP'

real	1m0.160s
user	1m35.453s
sys	0m27.772s

After:

$ time make generate-parallel 
(re)installing /home/stevekuznetsov/go/bin/bingo-v0.9.0
/home/stevekuznetsov/go/bin/bingo-v0.9.0 get -l
grep -rl 'go:generate' | grep -v 'vendor/' | xargs -P 0 -I {} bash -c 'go generate "./$(dirname {})"'
bindata.go
bindata.go
make imports
make[1]: Entering directory '/home/stevekuznetsov/code/Azure/ARO-RP/src/github.com/Azure/ARO-RP'
(re)installing /home/stevekuznetsov/go/bin/openshift-goimports-v0.0.0-20230304234052-c70783e636f2
/home/stevekuznetsov/go/bin/openshift-goimports-v0.0.0-20230304234052-c70783e636f2 --module github.com/Azure/ARO-RP
// ...
make[1]: Leaving directory '/home/stevekuznetsov/code/Azure/ARO-RP/src/github.com/Azure/ARO-RP'

real	0m17.770s
user	2m17.841s
sys	0m38.184s

I don't know necessarily what the benefits are for the built-in Go
generation stanzas, but `go generate` runs everything without
parallelism, which makes the `make generate` target very slow. We can
hack around this without asking anyone to stop using Go generate markers
by finding packages we need to generate and running them individually.
As long as the output is independent, this is safe.

Signed-off-by: Steve Kuznetsov <[email protected]>
@kimorris27
Copy link
Contributor

/azp run ci

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

.PHONY: generate-parallel
generate-parallel: install-tools
grep -rl 'go:generate' | grep -v 'vendor/' | xargs -P 0 -I {} bash -c 'go generate "./$$(dirname {})"'
$(MAKE) imports
Copy link
Contributor

Choose a reason for hiding this comment

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

This errors out for me saying the make target imports doesn't exist. What was this line supposed to do?

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.

2 participants