Live data from Hacker News

Go has added Valgrind support

go-review.googlesource.com

11–20 of 157 posts

Re: Go has added Valgrind support

#11

looks very promising, one of the biggest issue in golang for me is profiling and constant memory leaks/pressure. Not sure if there is an alternative of what people use now

How are you getting "constant memory leaks" in a GC'd language?

it's not hard. GC lets shit leak until it decided to clean it up...

do you think they will enable Valgrind if there's no leaks?

Re: Go has added Valgrind support

#13
post #9

[flagged]

> Next up: maybe Go will discover gdb integration and we can debug like it's 1999

That's already possible and documented[1]. I don't understand if you're sarcastic though, what's wrong with GDB? I use it in vim :termdebug and I wish all languages had native support for it.

[1]: https://go.dev/doc/gdb

Re: Go has added Valgrind support

#14
post #9

[flagged]

C is also half a century old. Perhaps Valgrind wasn't a high priority because the newer language also has newer tools?

Nothing wrong with adding tried and tested tools later if people want them.

Did you have a need for Valgrind in Go that wasn't served by any other tools until now?

Re: Go has added Valgrind support

#15
post #3

It only works if every package tests with it. Otherwise the relevant warnings get swamped by a huge amount by irrelevant warnings. This is why running Valgrind on Python code does not work.

If that were true it would also apply to C and C++. I have used Valgrind with Python + Boost C++ hybrid programs and it worked fine after spending an hour making a suppressions file.

Re: Go has added Valgrind support

#16

looks very promising, one of the biggest issue in golang for me is profiling and constant memory leaks/pressure. Not sure if there is an alternative of what people use now

How are you getting "constant memory leaks" in a GC'd language?

Golang has a feature that I love in general but that makes it very easy to keep unintended allocations around. If you have a struct with a simple int field, and you store that somewhere as an *int, the entire struct and anything it points to will be kept alive. This is super useful for short-lived pointers, and super dangerous for long-lived pointers.

Most other widely used GCed languages don’t allow the use of arbitrary interior pointers (though most GCs can actually handle them at the register level).

Re: Go has added Valgrind support

#17

looks very promising, one of the biggest issue in golang for me is profiling and constant memory leaks/pressure. Not sure if there is an alternative of what people use now

How are you getting "constant memory leaks" in a GC'd language?

There’s ways, GC isn’t perfect.

A common one I see fairly often is opening a big file, creating a “new slice” on a subset of the file and then using the “new slice” and expecting the old large object to be dropped.

Except, the “new slice” is just a reference into the larger slice, so its never marked unused.

Re: Go has added Valgrind support

#18

looks very promising, one of the biggest issue in golang for me is profiling and constant memory leaks/pressure. Not sure if there is an alternative of what people use now

How are you getting "constant memory leaks" in a GC'd language?

there are many ways:

    - you can create deadlocks
    - spawn goroutines while not making sure they have proper exit criteria
    - use slices of large objects in memory and pass them around (e.g. read files in a loop and pass only slice from whole buffer)
    - and so on

Re: Go has added Valgrind support

#19
post #7

looks very promising, one of the biggest issue in golang for me is profiling and constant memory leaks/pressure. Not sure if there is an alternative of what people use now

Ideally, they would have learnt from other languages, and offered explicit control over what goes into the stack instead of relying into escape analysis alone. As it is, the only way to currently handle that is with " -gcflags -m=3" or using something like VSCode Go plugin, via "ui.codelenses" and "ui.diagnostic.annotations" configurations.

I sometimes dream of a GCed language with a non-escaping pointer type. However to make it really useful (i.e. let you put it inside other non-escaping structs) you need something on the scale of the Rust borrow checker, which means adding a lot of complexity.

Re: Go has added Valgrind support

#20
post #4

> Instead of adding the Valgrind headers to the tree, and using cgo to call the various Valgrind client request macros, we just add an assembly function which emits the necessary instructions to trigger client requests. Love that they have taken this route, this is the way bootstraped toolchains should be, minimal building blocks and everything else on the language itself.

I am still curious, had they not gone this route, and avoided the other two routes mentioned, what could they have done to make this process as simple as the rest of Go tends to be, and nearly as performant? I guess this is an ongoing question to be solved at a future date.
Post reply on HN