Live data from Hacker News

Mid-stack inlining in the Go compiler

docs.google.com

21–30 of 76 posts

Re: Mid-stack inlining in the Go compiler

#21
post #8

It doesnt look like this solves inlining library calls?

Go statically links to all Go libraries, and only dynamically links when interfacing with C code. (As of the last time I used it, a couple years ago; this may have changed since then.)

Go nowadays supports dynamic linking, just plugins aren't 100% supported across all targets.

Re: Mid-stack inlining in the Go compiler

#23
post #19

This is interesting work! That said, it's a little disappointing when runtimes require custom algorithms or metadata to walk the stack and construct a stack trace. It makes it harder to build debuggers that grok the state of multiple runtimes (e.g., the Go code and the C code in the same program). This also affects runtime tracing tools like DTrace, which by construction can't rely on runtime support for help.

The plan is to add inlining information to the DWARF tables so that debuggers and other tools can take advantage of it.

Re: Mid-stack inlining in the Go compiler

#24
post #19

This is interesting work! That said, it's a little disappointing when runtimes require custom algorithms or metadata to walk the stack and construct a stack trace. It makes it harder to build debuggers that grok the state of multiple runtimes (e.g., the Go code and the C code in the same program). This also affects runtime tracing tools like DTrace, which by construction can't rely on runtime support for help.

We plan to expose all of the inlining information in the DWARF tables so debuggers won't have any problems with this. Internally, the runtime uses a different representation just so we can make it more compact and optimized for the runtime's exact needs. This way, you can also strip the debug info without breaking the runtime's own ability to walk stacks.

Re: Mid-stack inlining in the Go compiler

#25
post #8

It doesnt look like this solves inlining library calls?

Go already performs cross-package inlining, so it can already inline library calls. (This is relatively easy to do in Go compared to other languages because packages must form a DAG. Compiling package A writes out enough information in the object file for A that compiling package B that depends on A can inline calls to functions in A.)

Re: Mid-stack inlining in the Go compiler

#26

What impact would that have on build times? I know a lot of work has gone into getting back to 1.4 build times, but would the added work of inlining prolong builds?

The compiler got a bit slower:

https://github.com/golang/go/issues/19386

Those numbers are just for my CLs that fix stack traces but with mid-stack inlining still off. Turning it on makes builds noticeably slower:

    $ time ./make.bash
    real: 45.32s  user: 118.67s  cpu: 5.85s

    $ time GO_GCFLAGS='-l=4' ./make.bash
    real: 64.51s  user: 167.04s  cpu: 7.12s
We'll need to tweak the inlining heuristic to find a good balance between performance, build times, and binary size.

Re: Mid-stack inlining in the Go compiler

#28

9% faster, 15% bigger. I'll take that!

FWIW: This is actually not that great, but it's a good start.

You should be able to get about 15-20% with about 3-5% binary increase size.

In fact, with ThinLTO, we often see that gain with binary size decrease from smart inlining choices.

(The heuristics for inlining take a very very long time to get right and tune)

The issue they will next hit is that inlining is going to make the compiler slower until they tune the heuristics well.

Re: Mid-stack inlining in the Go compiler

#29
post #26

What impact would that have on build times? I know a lot of work has gone into getting back to 1.4 build times, but would the added work of inlining prolong builds?

The compiler got a bit slower: https://github.com/golang/go/issues/19386 Those numbers are just for my CLs that fix stack traces but with mid-stack inlining still off. Turning it on makes builds noticeably slower: $ time ./make.bash real: 45.32s user: 118.67s cpu: 5.85s $ time GO_GCFLAGS='-l=4' ./make.bash real: 64.51s user: 167.04s cpu: 7.12s We'll need to tweak the inlining heuristic to find a good balance between…

But then the compiler gets faster once you compile it with these new improvements. Is that accounted for in the issue?

Re: Mid-stack inlining in the Go compiler

#30
post #20
post #18

This is absolutely fantastic work. Since I've learned about continuation passing style (which Go channels could probably be formally transformed into), I've been convinced that there's a better way to do codegen. Better calling convention, better stack representation, better instruction architecture; I'm not yet sure - it's a nag continuously at the back of my mind, almost as though it's at the tip of my tongue. In t…

Are you aware of "Compiling with Continuations? https://www.amazon.com/Compiling-Continuations-Andrew-W-Appe...

That's an interesting read. One of only a handful of tech books I've read twice. It's thin and doesn't repeat itself all that much so if you read it twice it's still faster than reading most tech books once.

More recently though I heard someone proved mathematically that CPS can be transformed one-for-one into one of the more conventional models. That doesn't mean it might not still be easier for the humans to deal with however.

Post reply on HN