16 ms·
Sub-millisecond GC pauses in Go 1.8
- psyc 10y agoIf someone could do this for Unity, it would change my life.
- pcwalton 10y ago.NET already has concurrent garbage collection: https://msdn.microsoft.com/library/ee787088(v=vs.110).aspx#background_garbage_collection https://msdn.microsoft.com/library/ee787088(v=vs.110).aspx#b... See the "SustainedLowLatency" mode for something very similar to what Go does (although .NET's GC, unlike Go's GC, is generational, which is a significant difference).
- squeaky-clean 10y agoUnfortunately, Unity still uses .NET 2, and their next planned upgraded (to 4.6) is still listed as an undetermined eta. That's good to know for the future though.
- ijk 10y agoThey're beta-testing .NET 4.6 in Unity 5.5: https://forum.unity3d.com/threads/upgraded-mono-net-in-editor-on-5-5-0b9.438359/ https://forum.unity3d.com/threads/upgraded-mono-net-in-edito...
- kbenson 10y agoDoes unity actually use the .NET runtime, or mono? I was under the impression it used mono. Does that apply for mono?
- johncolanduoni 10y agoDepends on the platform you are targeting. Mono's GC (last I heard, they may have integrated .NET Core's by now) is relatively primitive. It was mostly developed just to have something better than Boehm. Their experience was actually pretty instructive; with their first release of the new GC (a proficient but basic generational collector) they still weren't beating Boehm all the time, and usually weren't beating it by much. Given its constraints, Boehm's GC is impressively optimized when you run it in semi-precise mode.
- pcwalton 10y agoWere they bump allocating in the nursery? That's where you tend to see the biggest gains from generational GC.
- johncolanduoni 10y agoYes, they even used TLABs. I believe the issue was that Xamarin was more interested in mobile performance at the time when SGEN was seeing heavy development and preparing for release, so they optimized for memory usage instead of throughput. The generational part was probably more of a hindrance than a benefit at that point in the process.
- marktangotango 10y agoVery interesting, I'm interested in how you came to this understanding. How did acquire information about this? Did they blog about it, or do you happen to follow their mailing lists, or ... ?
- johncolanduoni 10y agoI read a blog post from someone at Xamarin with some test cases graphed, a bit before Xamarin started suggesting SGEN as the default. I'll see if I can find the one I'm thinking of.
- matthewwarren 10y ago.NET also has the TryStartNoGCRegion API, which allows you too prevent all GC collections (for a certain while). See http://mattwarren.org/2016/08/16/Preventing-dotNET-Garbage-Collections-with-the-TryStartNoGCRegion-API/ http://mattwarren.org/2016/08/16/Preventing-dotNET-Garbage-C... for the full details
- weberc2 10y agoYou can do this in Go as well: https://golang.org/pkg/runtime/debug/#SetGCPercent https://golang.org/pkg/runtime/debug/#SetGCPercent
- pjmlp 10y agoThe problem is that Unity doesn't use a modern .NET runtime at all, rather the frozen Mono version from back when the Mono developers where still working for SuSE.
- forrestthewoods 10y agoI've never been more careful to avoid any allocation as I have been in Unity. I had fewer memory concerns in C++ for crying out loud.
- ChrisClark 10y agoSeriously! Once they've fully upgraded .NET and the GC, we'll all sigh in relief.
- psyc 10y agoI would 10,000x rather have to match new with delete (big deal) than to maintain the revolting unidiomatic contortions I'm obligated to do to outwit the GC.
- JoeAltmaier 10y agoThis. Times 100,000
- forrestthewoods 10y agoAgreed x10000. For VR we must maintain strictly zero garbage generation. Which is really damn hard in a language built on the assumption of GC.
- CyberDildonics 10y agoIn modern C++ you don't even have to do that.
- psyc 10y agoFor anyone else who's in this hell, this is the best reference I know of about how you have to write C# when the GC hates your data: http://stackoverflow.com/a/14277068 http://stackoverflow.com/a/14277068 tl;dr - "arrays of structs are really the only bulk storage method available in C#"
- rayiner 10y agoVery impressive. I wonder how Go manages to even stop all threads in 100 microseconds, much less do any work in that time.
- pcwalton 10y agoTo stop the world, Go preempts at the next stack size check [1], which happens during function call preludes. I guess that happens often enough to be fast in practice. [1]: https://github.com/golang/go/blob/8f81dfe8b47e975b90bb4a2f8dd314d32c633176/src/runtime/proc.go#L3900 https://github.com/golang/go/blob/8f81dfe8b47e975b90bb4a2f8d...
- rayiner 10y agoI assume this works so quickly in part because goroutines are backed by a pool of OS threads that don't block? So everybody doesn't get stuck waiting for a thread that's blocked to get around to checking the preemption flag?
- pcwalton 10y agoRight, blocked threads are stopped in the userspace scheduler so there are no synchronization issues with just keeping them stopped.
- johncolanduoni 10y agoOther systems I'm aware of that are capable of similar feats (I know .NET's collector can, not sure about Hotspot's) use page poisoning. Basically the compiler/JIT puts a bunch of extraneous memory accesses to a known address at key points where the GC can track what all variables and registers hold (called "safepoints"), in a fairly liberal pattern around the code. When the GC wants to stop all the threads in their tracks, it unmaps the page holding that address, causing segfaults in every thread it it hits one of the safepoints. The GC hooks the segfault handler, and simply waits for all threads to stop. I'm not sure that's what Go does, but I'm not aware of a faster way on standard hardware.
- bitmapbrother 10y ago.1 of a millisecond is very impressive. Does this mean Go can finally be considered a systems programming language?
- aikah 10y ago> .1 of a millisecond is very impressive. Does this mean Go can finally be considered a systems programming language? Can you write an OS kernel in Go ? no Go's runtime still depends on a OS. And whoever talked about Go as a system language didn't have kernels in mind, but "network infrastructure".
- pjmlp 10y agoOf course you can, time to learn about Mesa/Cedar, Modula-2+, Modula-3, Oberon, Sing#, System C# and possibly a few others. Here you can learn how those guys at Swiss Federal Institute of Technology in Zurich did it. http://people.inf.ethz.ch/wirth/ProjectOberon/index.html http://people.inf.ethz.ch/wirth/ProjectOberon/index.html Basically the runtime is done bare metal thus becomes the OS kernel. Oh, and Oberon wasn't just a research OS, it was actually used across the computing department by many of its employees.
- 4ad 10y agoYou can absolutely write a kernel in Go, many year ago Go used to ship with a bare metal runtime, as a demonstration...
- Someone 10y agoGo needs a runtime, but it need not be a full OS; it could be a not too big library that gets linked to a kernel written in go. Similarly, can you write an OS kernel in ISO C? No, you still need some assembly or runtime support. For example, ISO C doesn't have any notion of making syscalls or returning from the kernel to a caller or for setting up page tables. Any argument why go isn't suitable for systems programming along these lines should be about how much and what kind of runtime is acceptable for a systems programming language. A (fairly popular, I think, but certainly not universally agreed upon) argument could be that systems programming languages cannot have garbage collection because it should be possible to implement a garbage collector in them, and doing that in a language that already has one is possible but silly.
- bluejekyll 10y agoIf only there were generics, and no nulls, oh and strongly typed errors... regardless, this is Very impressive.
- polymathist 10y agoWhat about the way Go handles errors today makes them not "strongly typed"?
- swort 10y agoTyped vs untyped nil means that, in practice, all functions must return an error of type 'error', and force clients to downcast at runtime: https://golang.org/doc/faq#nil_error https://golang.org/doc/faq#nil_error Of course, there are ways around this such as returning a struct, but then that's no longer compatible with the error interface.
- mixedCase 10y ago> Of course, there are ways around this such as returning a struct, but then that's no longer compatible with the error interface. Which your struct can easily fulfill. That's the beauty of Go interfaces.
- swort 10y agoThe linked FAQ specifically talks about returning pointers to structs that fulfil the 'error' interface and why it's a bad idea.
- mixedCase 10y agoThe return type would still be the error interface. If you want more information than the error interface you can just use a type switch/assertion.
- lobster_johnson 10y ago
- enneff 10y agoThe proposal document for this change is a good read: https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md https://github.com/golang/proposal/blob/master/design/17503-...
- 4ad 10y agoThe canonical URL is: https://golang.org/design/17503-eliminate-rescan https://golang.org/design/17503-eliminate-rescan
- bitmapbrother 10y agoBrief synopsis: Go 1.8 is moving to a hybrid write barrier in order to eliminate stack rescanning. The hybrid write barrier is equivalent to the "double write barrier" used in the adaptation of Metronome used in the IBM real-time Java implementation. Some benchmarks: https://github.com/golang/go/commit/bd640c882a8dcb88a0497770f881bce48ab83102 https://github.com/golang/go/commit/bd640c882a8dcb88a0497770...
- bluejekyll 10y agoPeople are down voting this, is it incorrect?
- morecoffee 10y agoI like faster latency as much as the next person, but these improvements aren't free. On my own servers I notice approximately 20% of CPU time spent in GC.
- jemfinch 10y agoI'm a C++ programmer who hates garbage collection on general principle, but I have to say: 20% of CPU time spent in memory management isn't all that unusual (especially in software that hasn't been optimized), whether or not that memory management is automatic garbage collection or manual.
- foota 10y agoIt drastically changed my perspective on gc when I realized that it's really not much slower, it just batches the slowness.
- btmorex 10y agoThat's true for GC vs. manual heap-based memory management, but most GC languages don't do stack allocation at all or only for primitive types and stack allocation is much, much faster than any sort of heap-based memory management.
- foota 10y agoThat's fair. Does Go do this? Or any other somewhat mainstream language? Any thoughts on how arenas (rust) compare to gc and manual allocation for speed?
- kasey_junk 10y agoC# & Go both have stack allocation options. The JVM is supposedly getting them sometime soon.
- 10y ago
- jgalt212 10y agoCan one write an HFT application in Go now?
- cheepin 10y agoIf you are measuring response in nanoseconds, 100 microseconds is still a lot. However, it may be good enough for games at well below 1% of your time budget for a 60 fps game assuming cache locality is good enough so you don't waste too much time fetching from main memory.
- Matthias247 10y agoBesides games it would be interesting how good Go would now work for things like low-latency audio processing (single-digit-millisecond-latency). That's some kind of classic domain where performance is not a problem but once you miss the target timeframe you are pretty fucked up (producing and hearing glitches).
- chillydawg 10y agoI write a fair amount of low latency code in go, but none of it is hard real time. Average throughput of a few microseconds (for my simple workloads) with spikes of milliseconds here and there is what I tend to find. Fine for a lot of things but I'd be hesitant to use it for high fi audio apps that are very sensitive to latency. Humans may only be able to notice 50ms, but if you're chaining DSP you can end up with a fair bit of variance in your processing pipeline.
- pjmlp 10y agoHere is a demo from IBM doing audio processing with their real time GC in Java. http://researcher.watson.ibm.com/researcher/view_group.php?id=174 http://researcher.watson.ibm.com/researcher/view_group.php?i... Already in 2012, so even if not yet there, I think Go can get there, specially since you can take care to just stack allocate and minimise GC use during the hot tub path.
- kasey_junk 10y ago
- gok 10y ago"typical worst-case" So... not worst-case. :) Regardless, very impressive achievement, especially given that they've been able to do it without a JIT or exotic tricks like Azul.
- dpark 10y agoOf course not. You can't put absolute worst case times on code in practice. Worst case might be that someone managed to load 80PB of RAM on a CPU underclocked to 50 MHz. Or that the OS suspended the process in the middle of GC and was promptly frozen for a week while VMs were migrated across the country in the cup holder of someone's Toyota. Worst case in absolute time always requires ignoring pathological cases.
- taeric 10y agoThis feels very wrong to me. Qualifying it with some sort of analysis is fine. Just saying "typical" is borderline negligent and is why nobody just uses naive quicksort in production systems where runtime can actually matter.
- klodolph 10y agoWhat's the alternative? We don't care about worst-case latency in practice, and average case is often ignored as well. We look at 99.9% latency numbers or things like that. Worst-case is for people designing pacemakers or rockets, that's not what we are doing here.
- kuschku 10y ago> that's not what we are doing here. Considering this code will likely be used in IoT, yes, this is what we’re doing here.
- grogenaut 10y agoPretty sure web enabled cameras are NOT pacemakers NOR rockets... heck they can't even put a different password on each device by printing on a sticker. Nor is my sous vide machine or anything else I've seen as an IoT device. I wouldn't call say my oscilliscope an IoT device even if it can connect to wifi. It's a scientific device with cloud upload.
- yelnatz 10y agoDoes anyone have any write ups for GC algorithm comparisons? E.g. Java vs Go vs C# vs Actionscript vs Javascript?
- cryptrash 10y agoMan, remember when GC pauses were >1ms? >10ms? >100ms? How far Go has come! Goes (yup) to show you how much actual engineers can accomplish versus a team of ex-rubyists with no clue. I'm excited now for the Go language itself to advab
- cryptrash 10y agoMan, remember when GC pauses were >1ms? >10ms? >100ms? How far Go has come! Goes (yup) to show you how much actual engineers can accomplish versus a team of ex-rubyists with no clue. I'm excited now for the Go language itself to advance a little bit. Little bit more sugar and spice to it, and I think it'll be as pleasant to work with as Julia or Python or other languages with really tight tooling. Not that go tooling isn't good, but it feels like putting racing slicks on a civic sometimes, if Go was just a little bit more fun to write, it'd go a long way.
- bishop_mandible 10y agoWow, makes me want to develop a AAA game in Go.
- chillydawg 10y agoI get why you're saying this, but go-to-c bindings are not fun and that's how you'd have to talk to the hardware.
- Narishma 10y agoWhat makes a game AAA is the resources (human and financial) that were used making and marketing it, not the language used to write it.
- pjmlp 10y agoAnd the culture. AAA game developers only moved from Assembly to C, Pascal when forced to do it. A few years after they moved from C to C++ when the SDKs started to be C++ only. Similarly they will only move from C++ when forced to do so, and they only major complaint is related to build times. I bet most are willing to wait until C++20 for modules than switching to another language, even if some studios manage to have some hits developed in safer languages.
- zubat 10y agoVery good point here The outlook of gamedevs to new tooling tends to be pessimistic because so little is actually geared towards what they work on, or want to work on. On the other hand, Web and mobile games have lived with the consequences of a managed runtime for many years now. There are limits in how much processing power is available there, but it ultimately just diverts developer attention towards other things like a more robust backend, faster turnarounds, and other general workflow improvements independent of scene fidelity.
- mangeletti 10y agoDoes this mean Go could be more suitable for robotics and drones now?
- TheCrott 10y agoFor IoT there's a package for that