News for hackers. Stuff that matters.
Re:Practices for writing high-performance Go by ryanworl on Monday May 06, 2019 @11:02AM (#19840054)
That is still a useful tool in Go, but you don’t need to use it as much as you’d think. The GC is pretty good at short-lived objects. The canonical implementation is sync.Pool if you don’t want to build one yourself.
Re:Practices for writing high-performance Go by weberc2 on Monday May 06, 2019 @01:27PM (#19841684)
Usually I use pools to avoid the allocation cost. The GC sweep is not usually my problem.
Re:Practices for writing high-performance Go by naikrovek on Monday May 06, 2019 @05:45PM (#19844237)
Profile it and see if it is a problem in Go, I would say.

I don't know if the Go runtime has optimizations for this kind of thing inherently, and it might.

Profile, and see.

Re:Practices for writing high-performance Go by weberc2 on Monday May 06, 2019 @06:17PM (#19844497)
That's ... not helpful. I already profile and profiling indicates that allocations are slow and sweeps are fast.

Go's optimization for this is escape analysis which is a best-effort attempt to put things on the stack. Because the stack analysis is naive (which isn't necessarily a bad thing), it means lots of things are still allocated on the heap, and those are the allocations I'm referring to.

Re:Practices for writing high-performance Go by kasey_junk on Monday May 06, 2019 @06:26PM (#19844555)
The bigger issue is usually stack vs heap allocation and it’s hard to reason about that. But the good news is that unlike a JIT system you can actually pretest golang escape analysis.

Look at the -m gcflag to see what is escaping, then see if that is where the allocation hotspot is. If so see if you can get the escape to happen where you want.

Otherwise you need to go no allocation. Notice that go actually gets _worse_ over time generally at heap allocation so it’s likrly worse than early profiles suggest.

Re:Practices for writing high-performance Go by weberc2 on Tuesday May 07, 2019 @10:23AM (#19849649)
> The bigger issue is usually stack vs heap allocation and it’s hard to reason about that.

I don't think it's especially hard to reason about in the main cases, and when you're unsure (as you mention) you can actually print out the escapes. Would be really interesting to have an editor that would show you where things were escaping (although that could easily lead to premature optimization).

Re:Practices for writing high-performance Go by GordonS on Thursday May 09, 2019 @02:04PM (#19870582)
.NET has the ability to allocate on the stack, using `stackalloc` - does Go have a similar feature?