Hi all, golang questions - I'm just getting starte...
# general
v
Hi all, golang questions - I'm just getting started with trying out pants, and converting existing projects and modules, and I'm seeing two problems. 1) Very high memory use, I streamlined to reproduce, and just including one or two large modules in go.mod churns though 10GiB of memory on each
check
. 2) Possibly as a result, the caching gets busted - re-running check without changes validates all the dependencies again. I'm setting this up as a public github module - I just wanted to check what other details are helpful to include in a bug report.
🙏 1
(running pants 2.18.1 on ubuntu)
h
What you provided is very helpful, thanks!
👍 1
l
Sharing my "hack" for hiding Golang code in multi-language repos. 1. Sperate
go_module
target into a separate BUILD file (like
go.BUILD
) 2. Make sure Golang code is not mixed with other language code (as store them in separate directories) 3. In
pants.toml
update build patterns and add an alias to tweak it, for instance:
Copy code
[GLOBAL]
build_patterns = [
  "BUILD",
  "BUILD.*",
  # Enable Golang builds by default.
  "go.BUILD",
]

[cli.alias]
disable-go = "--build-patterns=\"['BUILD', 'BUILD.*']\" --build-ignore=\"['./path/to/your/go/code/*']\""
Now, you can add
disable-go
to your Pants command, and get faster execution, if you are only working with other languages. For example
pants disable-go tests ::
. The difference (with cached results) for me was around 80s speedup.
Copy code
# With Golang
84.52s user 17.61s system 308% cpu 33.094 total

# Without Golang
6.55s user 0.50s system 98% cpu 7.157 total
👍 2
👀 1
h
That's an excellent hack. Could you post this as a workaround on https://github.com/pantsbuild/pants/issues/16445 ? I have a feeling we might want to document this
👍 1
1
🎉 1
m
Any update on improving this? I would love to contribute but I don't really have any insights on how pants work. Why would go-related stuff be invoked when the target does not contain any go code?
h
Because of dependency inference. Right now Pants isn't smart enough to know that it will never infer a dep from a .go file to a .py file or vice versa