-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
internal/gopathwalk: Ignore Bazel symlinks #118
Conversation
Signed-off-by: Vince Prignano <[email protected]>
This PR (HEAD: e101897) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/tools/+/182417 to see it. Tip: You can toggle comments from me using the |
Message from Gobot Gobot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Heschi Kreinick: Patch Set 1: I guess GOPATH is set to the root of your Bazel workspace? Have you considered checking in a .goimportsignore instead? Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Vince Prignano: Patch Set 1:
In this case, GOPATH=$HOME/go and the workspace directory is $HOME/go/sigs.k8s.io/cluster-api The issue I found with .goimportsignore is that it doesn't allow (afaik) to specify regex-style ignore, but instead it's a list of paths. The Bazel directories are temporary dirs which are randomly generated. Does that help? Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Vince Prignano: Patch Set 1:
One example from cluster-api: bazel-bin -> /private/var/tmp/_bazel_vince/be0cbd1c3f18d98f10f1daad792debc4/execroot/main/bazel-out/darwin-fastbuild/bin/ Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Heschi Kreinick: Patch Set 1:
It should be valid to put a symlink in .goimportsignore. Does adding each of bazel-out,genfiles, etc not work? When you run goimports -v you should see a line like "Directory added to ignore list: bazel-out", which indicates it's successfully statted the symlink and added it to the list of things to not enter in shouldTraverse. Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Vince Prignano: Patch Set 1:
Thanks for the reply, I tried and indeed it shows that the bazel-out is ignored. That said, the filter work only in this specific repository. Working with Kubernetes project, every repository has its own Bazel workspace and bazel files. Goimports (gopathwalk) seems to scan the entire GOPATH multiple times and the bazel-* folders (in other repos) affect the overall performance as well. Given the lack of support for .goimportsignore to exclude directories based on a pattern, this change seemed necessary. Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Heschi Kreinick: Patch Set 1:
I would rather not add hardcoded rules for Bazel symlinks and dirs, especially since you can change them with --symlink_prefix. Please fully explain the problem you're trying to solve. Some questions I have: What does the GOPATH in use here look like, and where are the Bazel workspaces in it? Why can't you add a simple .goimportsignore to each repository? Why is this the right change vs. adding pattern support to .goimportsignore? Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Vince Prignano: Patch Set 1:
Hardcoded rules aren't great, fully agree. I (and others) usually work across a number of different repositories within the GOPATH, all of which use Bazel as build tool. To give a few examples:
The list goes on :). I can definitely write a script locally to dynamically search for the bazel-* symlinks and add them to my .goimportsignore one by one. I contributed this patch because others folks developing with Bazel project might experience the same behavior. Over time, more and more Kubernetes projects (and sub-projects) will opt-in to use bazel and the .goimportsignore will grow as well. If you think everyone should write their own automation to exclude these symlinks, that's fine and I'm fine closing this. That said, there are already hardcoded rules (e.g. emacs symlink files) and Bazel users can benefit as well. --vince Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Vince Prignano: Patch Set 1: Any updates on this patch? Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Vince Prignano: Patch Set 1:
Should we close this change? I don't have strong opinions, it seemed a good improvement from before. Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Heschi Kreinick: Patch Set 1: Sorry, I haven't had the time to get my thoughts together on this and I still haven't really been able to. https://golang.org/issue/30058 and https://golang.org/issue/30058#issuecomment-490252038 are related. I think I might prefer the idea of a per-module .goimportsignore for this case, but I really don't know. Doesn't goimports need to read from stuff in bazel-genfiles? Or is that not necessary because some Kubernetes always copies the wrapper back? Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
Message from Ian Lance Taylor: Patch Set 1: This seems related to https://golang.org/issue/30058. Please don’t reply on this GitHub thread. Visit golang.org/cl/182417. |
b1cdfd1
to
64da2da
Compare
For some folks working in the upstream Kubernetes community using goimports has been problematic. One example is working with the cluster-api repository. In the past few days I've noticed a significant slowdown across multiple machines (one with 16 cores) and started debugging.
Performing a CPU profile showed where the application was spending most of its time:
After further investigation, I was able to determine that the major slowdown was on repositories that were built and tested by Bazel. Bazel adds some symlinks to temporary folders when running in a project, which goimports scans as well.
Here is some simple benchmarks:
Runs pre bazel symlink ignore
Runs post bazel symlink ignore