News for hackers. Stuff that matters.
Re:Program your next server in Go by weberc2 on Tuesday June 07, 2016 @04:12PM (#11857413)
Have you considered pausing the GC for those blocks? Or am I misunderstanding your use case?
Re:Program your next server in Go by infogulch on Tuesday June 07, 2016 @04:30PM (#11857534)
How do you do this? I didn't know there was a way to temporarily disable the GC for specific blocks.
Re:Program your next server in Go by weberc2 on Wednesday June 08, 2016 @12:13AM (#11859962)
You can toggle the GC with https://golang.org/pkg/runtime/debug/#SetGCPercent. Turn it off before you enter your block and enable it again at the end of your block.
Re:Program your next server in Go by amelius on Wednesday June 08, 2016 @05:20AM (#11860991)
But can you guarantee that the GC actually makes progress that way?
Re:Program your next server in Go by AnimalMuppet on Wednesday June 08, 2016 @03:55PM (#11865122)
Maybe you can, but maybe you shouldn't.

That is, you do this if you want a block to run without the GC interrupting it. That is, it's a really high-priority (realtime, or close) block. When it needs to run, it's the most important use of the CPU. But if you demand that the GC makes progress, you're saying that it also is important. And it is, but it's less important than the critical block. If you don't say that, then you wind up with "everything is important", and that way lies madness.

But you may be able to do it. You need enough CPU bandwidth that you can run your critical sections and spend enough time outside them that the garbage collector keeps up. (And then, every time you add to your code, you need to make sure that the CPU still has enough time...)

Re:Program your next server in Go by weberc2 on Wednesday June 08, 2016 @01:08PM (#11863766)
What does it mean for a GC to "make progress"? My understanding was that the OP wanted to stop the GC for a particular code block, so it would seem that any "progress making" would be undesirable.
Re:Program your next server in Go by kyrra on Wednesday June 08, 2016 @12:05AM (#11859936)
https://golang.org/pkg/runtime/debug/#SetGCPercent

Do note that it triggers a GC when you call this, so it's not for all situations, but can be useful.