5 ms·
There's something funny about proudly proclaiming no GC and written in C++ for a golang IDE. It's not wrong; different tradeoffs for different uses. Just funny.
by yjftsjthsd-h 5y ago
There's something funny about proudly proclaiming no GC and written in C++ for a golang IDE. It's not wrong; different tradeoffs for different uses. Just funny.
- bob1029 5y agoModern GC doesn't even preclude the possibility of developing a no-lag UI. You just have to be very careful with how you manage your data so that you don't get hit with more heavy-handed collection mechanisms (i.e. large gen2 cleanups in .NET). Small and short-lived class instances (more ideally structs) are the key to success with low-latency applications in most GC'd languages. If you are only touching gen0/1 in a .NET5 app, you will probably find the GC impact to UI latency to be negligible. In .NET, avoiding gen2 allocations is pretty easy. The biggest thing is replacing every byte[] with Stream as feasible, so you don't send objects directly to LOH (gen2). I believe the LOH threshold for byte[] is lower than the published limit of 85k, but I cannot recall the specifics (might be closer to 10k). Regardless, you really shouldn't be holding onto chunks of memory that large if you can ever avoid it. In some cases you can cheat. Pass around the path/id to a file and then stream it from disk at the very last possible moment (i.e. copy a FileStream direct to the HttpContext.Response.Body stream). If you absolutely must allocate large objects, try to reuse them as much as possible. Act as if anything entering gen2 is in memory forever, because with enough LOH fragmentation, it might as well be. UI is one thing, but real-time process control is a wholly different animal. If you want to write a PID in a GC language, you better be prepared to eschew any notion of allocation in the process under collection. Even if you don't allocate, there are runtime components that still will, so you will almost always have some minimum amount of noise to contend with. That said, if you only need to run a PID loop at ~10khz (100uS loop delay), you probably wont have any issues. Just make sure you put the PID loop on a high-priority thread and care for its surroundings gingerly. A Raspi4+ is actually an amazing platform for this sort of thing.
- throwaway894345 5y agoI suspect Go's GC would be particularly well-fit for this kind of application considering it typically runs in <1ms with no exceptionally large pauses (except perhaps in pathological cases). Like C#, Go has value types, so controlling allocations should be pretty straightforward.
- throwaway34241 5y agoI had the same thought, it probably wouldn't even interfere with their stated goal of running at 144fps (and of course there would be more Go code analysis libraries available in the Go ecosystem). I could imagine plenty of other reasons to go with C++ though - there's still going to be a higher performance ceiling, maybe they plan to support languages other than Go, maybe they want a minimal file size compiling to WASM or to use specific C++ libraries etc. It would be interesting to see the original author's thinking behind it, on the website it's mainly comparing C++ to web technologies.
- sk0g 5y agoThe Micro [0] editor is written in Go as well, which I was surprised by. It's a tidy piece of software, usually install it to replace nano. [0] https://github.com/zyedidia/micro https://github.com/zyedidia/micro
- noch 5y ago> I suspect Go's GC would be particularly well-fit for this kind of application considering it typically runs in <1ms with no exceptionally large pauses (except perhaps in pathological cases). Lol. " 30% of CPU cycles were being spent in function calls related to GC. " https://blog.twitch.tv/en/2019/04/10/go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap-26c2462549a2/ https://blog.twitch.tv/en/2019/04/10/go-memory-ballast-how-i...
- jrockway 5y agoThe raw CPU time used doesn't really matter if it doesn't cause the UI to block. It does for server applications; needing 30% more cores costs 30% more money, which you could use for something else. But for tiny programs that run on your workstation, using 1.3% CPU doesn't cost more than 1% CPU. You do have to watch out for the case where you can't use all the cores, and GC is blocking actual computation the user wants to perform. (Also, you're at about 4000 cores when saving 30% buys you another developer. So you have to think about when the right time to unlock that money is, and how much it costs to unlock.) I've been writing a game in Go. The GC doesn't prevent me from getting a smooth 360 frames per second. 1ms is a substantial pause, but isn't even a missed frame.
- Aeolun 5y agoI can write basically instant local electron code. I've never seen anything close to problematic GC. Maybe other people have issues with their app responding in 5 instead of 1ms?
- gregors 5y agoI remember this discussion https://github.com/Microsoft/vscode/issues/22900 https://github.com/Microsoft/vscode/issues/22900
- gameswithgo 5y agoOften the difference is between small personal projects where performance can easily be kept under control, whereas large production products, that have to handle all the edge cases, accessibility, work on many platforms, etc etc can be quite a bit more complex, require more people working on it, and performance gets harder to keep under control. That last 10% to can be 90% of the complexity and work. Text editors, especially with language aware features, are far from simple.
- pjmlp 5y agoSoft real time GCs do well enough to replace C++ with Java in battleship and ground control missile targeting systems, as PTC, Aonix and Aicas have been doing for years. A frame drop causes little more hazard than just an unhappy gamer. Speaking of which, many keep forgetting that Unreal C++ and Blueprint make use of GC.
- kaba0 5y agoJust as another data-point, java now has ZGC and Shenandoah low-latency GCs that basically sacrifice some throughput for better latency (read barriers instead of write), but the former can already achieve <1 ms global pauses, which is shorter than what the OS scheduler itself can cause. Of course one should never “spam” the GC needlessly, but it does work for up to quite big heap sizes.
- bob1029 5y agoZGC is a very compelling option for applications that get periodic restart opportunities (or are of the cruise missile guidance computer variety). In places where you have to use reference types, sometimes you can allocate everything you should ever need up-front and then pull from that pool of pinned instances throughout the day. Pre-allocating all of your required memory can provide more deterministic outcomes.
- cjwoodall 5y agoI would contend that 10kHz is pretty fast for a control loop thats doing anything complicated in a Garbage Collected language on a non real-time OS. The later issue being some what of a bigger issue than the GC. You CAN do it... some of the Basic linux real time stuff helps the situation a lot. In .NET you can also change the GC policy at the thread level which can help a lot. Pool Allocation (long held chunks of memory that can be manually repurposed) can help a lot, since you can write custom Pools where the Gc never knows it needs to clean up. It is a useful tool when you have big chunks of memory that need to be manipulated at a high rates. I would say from experience that 500Hz-1kHz is a more reasonable loop time
- SiVal 5y agoIt is funny--a bit. Decades ago, I often used Perl to take a data table in some messy form and convert it into C source code, which I would combine with other C source that I wrote and compile into an executable. I thought it was ironic that I knew C well enough to write it and well enough to tell Perl how to write it, and it was still easier to tell Perl to write C than to tell C to write C. So, Perl is obviously a much better language. Except that it turns out it's a lot easier to write Perl itself (the interpreter) in C than to write it in Perl. So Perl is better, because it's better for "writing C", and C is better, because it's better for "writing Perl". The irony is still funny, but it is clearly based on a feeling that language goodness is one-dimensional, even when we know that any comparison of hammer and saw on a single dimension is going to miss most of what matters.
- thaumasiotes 5y agoI had a cryptography professor recommend for one assignment that, instead of trying to recognize the correct plaintext by its similarity to English (an approach that yielded results that could be manually adjusted into the correct plaintext, but wasn't able to find the plaintext by itself...), I should try to disqualify incorrect plaintexts by recognizing them as non-English. The approach there was just to ingest a long book from Project Gutenberg, record all of the trigrams (including across word boundaries), and disqualify a candidate plaintext if it had more than some low number (3, but it was a short text) of unrecognized trigrams. This worked beautifully. For reasons I don't recall, I wrote the assignment in C. I didn't want to do the parsing of the book into a trigram table in C. So I did that separately, and emitted C code to assign to a three-dimensional character array for every trigram I found. Then my assignment was the concatenation of some code initializing the array to zeros, the emitted code adding ones to it, and, thousands of lines later, the actual decryption code.
- pjmlp 5y agoIndeed, that is just a complete disservice to the language.
- eyelidlessness 5y agoIt’s about as funny as one of the most prominent alternative TypeScript compilers being written in Go, and being performance competitive with the other one written in Rust. Equally not wrong, just… not the way I thought things would, erm, go.
- pantulis 5y agoKind of surprising, yes. But also proves the point that whatever is your love language, you should still be using the best tool for the job. And the developer felt it was C++.
- mhd 5y agoHonestly, the amount of work that's spent in the industry to (often needlessly) avoid GC has stopped being funny a long time ago for me.
- skocznymroczny 5y agoReminds me of people who switch to D and first thing they look for is how to escape the GC