-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Speed up goimports usage #11896
Merged
SirGitsalot
merged 1 commit into
GoogleCloudPlatform:main
from
SirGitsalot:fasterimports
Oct 3, 2024
Merged
Speed up goimports usage #11896
SirGitsalot
merged 1 commit into
GoogleCloudPlatform:main
from
SirGitsalot:fasterimports
Oct 3, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi there, I'm the Modular magician. I've detected the following information about your changes: Diff reportYour PR hasn't generated any diffs, but I'll let you know if a future commit does. |
about to be OOO, can you take a look over this @zli82016 ? |
zli82016
reviewed
Oct 2, 2024
zli82016
approved these changes
Oct 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Amazing improvement.
This was referenced Oct 3, 2024
karolgorc
pushed a commit
to karolgorc/magic-modules
that referenced
this pull request
Oct 4, 2024
niharika-98
pushed a commit
to niharika-98/magic-modules
that referenced
this pull request
Oct 7, 2024
trodge
pushed a commit
to trodge/magic-modules
that referenced
this pull request
Oct 10, 2024
karolgorc
pushed a commit
to karolgorc/magic-modules
that referenced
this pull request
Oct 11, 2024
gontech
pushed a commit
to gontech/magic-modules
that referenced
this pull request
Oct 16, 2024
BBBmau
pushed a commit
to BBBmau/magic-modules
that referenced
this pull request
Oct 23, 2024
BBBmau
pushed a commit
to BBBmau/magic-modules
that referenced
this pull request
Oct 24, 2024
BBBmau
pushed a commit
to BBBmau/magic-modules
that referenced
this pull request
Nov 5, 2024
akshat-jindal-nit
pushed a commit
to akshat-jindal-nit/magic-modules
that referenced
this pull request
Nov 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.