Manual Memory Management in Go
deferpanic.com
deferpanic.com
We can't wait for Go 1.5 where the Stop-The-World GC goes away: https://docs.google.com/document/d/1wmjrocXIWTr1JxU-3EQBI6BK...
Regardless of my opinion about some Go issues, I really look forward to see the language becoming widespread.
My experience with Oberon back in the mid-90's, made me aware that it is possible to have systems languages with GC.
The main problem is that many developers don't experience the variety from GC implementations that exist out there, and equate all implementations alike.
In Oberon's case it wasn't the best GC in the world, specially in mid-90's PC hardware, but coupled together with value types it was good enough to fully implement an OS in Oberon (and its derivatives).
I should probably not just complain but explain
1. How to prove via pprof and other tools that you have problems related to memory allocation or GC.
2. Some strategies for addressing that problem that don't involve writing an allocator. Using sync.Pool or a recycler pattern. Keeping allocations on the stack etc...
3. How to write a allocation interface in Go for allocating arbitrary objects. Aka emulating New and Make.
4. How to write a allocator backed by a memory mapped files.
I have been working for a while in this space because of my academic research which involves frequent subgraph mining. That particular data mining problem is exponential and certain techniques can use a lot of memory. In order to scale my solution I have need to get the memory allocations under tight control. Sometimes I think I should just re-write in C++ or Rust but Go has provided me a lot of benefits from the concurrency angle so it isn't a win/win to move languages.
Maybe I will write up all of this stuff at some point. It is a bit much for an HN comment.
Maybe some information about how heap size and mutation rate affect GC would be interesting, as well as the future of the Go GC.
One interesting thing about Go is that if your objects contain no pointers, the Go GC does not have to scan them. So you can supposedly create huge slices of any type containing no pointers and the GC will have a much lower load on it.
There's a really good article from Dmitry Vyukov including memory related stuff here: https://software.intel.com/en-us/blogs/2014/05/10/debugging-...
.. So it's actually just an advertisement for their product, the title should really be something else, I feel a bit mislead initially assuming something useful might be had from reading the article.
The article repeatedly talks about how managing memory manually increases the risk of fragmentation. And that this risk somehow goes away with gc managed heaps.
...so garbage collectors don't also have to manage their own internal heaps and have fragmentation issues? Hm, not sure I buy this.
At the expensive cost of moving memory blocks around in the managed heap, there is no silver bullet.
In modern OSes, virtual memory plays an analogous role. We still have a double indirection, but it goes through the TLB and page table.
*real-time, embedded and gamedev for example. where us scale have as much importance as ms for other fields.
1. You have more domain knowledge about the objects you're creating so you can special case and beat malloc()/free()(which can be extremely painful in some cases).
2. You need to control the memory layout of your objects so that the data access patters line up with memory layout. The speed improvements here are on the order of 50-100x depending on your case.
Usually(but not always) GC'd languages don't give you value types that let you do #2. C# and a few others happen to be a nice exception. If you're using Java you end up being out of luck unless you decided to leverage a library that provides views into byte buffers like FlatBuffers. Although then you pay the indirection costs.
I haven't worked much with Go to know if it supports composing values types like C# but when we talk about performance that's usually what crosses a lot of GC'd languages from my list.
Or a certain fungi. :)
http://stackoverflow.com/questions/16494822/why-is-it-called...