Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now that the go compiler is live I've started toying with bazel, and the extra time that
goimports
adds to each compile run is irking me. This PR speeds things up by runninggoimports
once as a last compilation step rather than running it for each generated source file.goimports
performs two functions for us: removing imports that are declared but not used, and adding imports that are used but not declared. The former is fast, the latter is slow - like, a couple of orders of magnitude slower than the former. The difference exists because removing imports requires parsing only the go file that's being fixed, while adding imports potentially parses every go file in the project, the standard library, and in yourGOPATH
.goimports
has an internal cache that avoids some repetitive parsing, and by using a single execution that runs over all of the generated files at once we're able to leverage that cache.Here's some example timings on my M1 Macbook Pro. Before:
After:
YMMV of course, and full builds benefit a lot more than single product builds.
Ultimately the best way to speed up the compiler will be to include all imports that we're using, and the change to
resource.go.tmpl
picks the lowest hanging fruit (for context, 10 seconds of the speed up on my machine came from just those five lines). The new--show-import-diffs
flag is useful for identifying the files that need import fixes.Derived from GoogleCloudPlatform/magic-modules#11896