News for hackers. Stuff that matters.
Re:Crystal: Fast as C, Slick as Ruby by ghayes on Thursday August 04, 2016 @03:08AM (#12223921)
One of the largest areas of concern is for real-time systems (systems which fail if they do not respond within some small time threshold). Most GC involves stopping the world to perform the GC which can pause your program's execution for some number of milliseconds. If GC pauses exceed your real-time requirements, you're out of luck.

Some languages, like erlang, do slightly better by garbage collecting erlang processes individually, so other erlang processes can continue running during GC.

Re:Crystal: Fast as C, Slick as Ruby by Matthias247 on Thursday August 04, 2016 @01:05PM (#12226957)
For hard realtime systems it actually doesn't matter anymore. These are mostly implemented with a "don't allocate at all" strategy, since every allocation is not determistic. Therefore things are mostly statically allocated and bounded. And maybe there are some objects pools are around. You can do this in Go in the same way as in C. The only question there is if the GC will still run in the respective languages if no allocations happen through the user (e.g. because the runtime could do allocations in the background for it's housekeeping).
Re:Crystal: Fast as C, Slick as Ruby by mike_hearn on Friday August 05, 2016 @09:03AM (#12231939)
Yeah, the idea that malloc/free "don't pause" can only be based on not understanding how mallocs actually work. Advanced mallocs are often even multi-threaded and do some work on background threads.

Hard-realtime is always "allocate everything up front". It has to be. Allocation of dynamic sizes is not a problem you can make fully deterministic.

Re:Crystal: Fast as C, Slick as Ruby by Svenskunganka on Thursday August 04, 2016 @03:31AM (#12224000)
This is known, but it's always possible to overcome these situations and its part of the language maturing. Golang has already had its run with optimizing their GC for real-time systems. Twitch uses Golang for their IRC chat, and they've taken the Golang GC on a journey which you can read about here: https://blog.twitch.tv/gos-march-to-low-latency-gc-a6fa96f06...

Crystal will at some point also be forced to optimize their GC for these cases, although it currently uses an out-of-the-box GC called Boehm-Demers-Weiser conservative garbage collector http://www.hboehm.info/gc/ which they have acknowledged they need to replace sooner or later.

Re:Crystal: Fast as C, Slick as Ruby by pcr0 on Thursday August 04, 2016 @03:37AM (#12224026)
The parent comment is referring to hard real-time systems (where not responding within a certain timeframe would lead to catastrophy). We're talking things like pacemakers, anti-lock brakes, industrial control systems.

Regardless of how good GC is you would never use it in a hard real-time system because it is non-deterministic. IRC chat is only soft real-time.

Re:Crystal: Fast as C, Slick as Ruby by adrianN on Thursday August 04, 2016 @04:01AM (#12224123)
Those kinds of systems won't get compilers for something other than C/C++ or maybe Ada for a long time. Usually you're stuck with a compiler from the chip vendor that kinda-sorta supports C.
Re:Crystal: Fast as C, Slick as Ruby by lomnakkus on Thursday August 04, 2016 @05:26AM (#12224384)
Indeed, and you'll probably also need a special-purpose RT OS stack (or have to write your own/go without).

EDIT: I'd also add that this is such a niche[1] area of programming that expecting any mainstream language to meaningfully support it is... optimisitic and that mainstream languages shouldn't try to support it. (Soft real-time may be reasonable, but I believe that can be achieved with GC as demonstrated by the Azul JVM.)

[1] Niche, but obviously important, but perhaps not lucrative enough for anything to displace C or perhaps Ada -- given that these industries tend to be extremely conservative. (I wonder if ATS is used, though. Can't claim it's pretty, but proof seems like it would be a good thing for these systems?)

Re:Crystal: Fast as C, Slick as Ruby by pjmlp on Thursday August 04, 2016 @12:10PM (#12226506)
Special versions of Java also get into this niche. Check the PTC Java compilers or Websphere Real Time one from IBM.

Before Aonix got bought by PTC they had a few contracts for weapons control for missiles and battle cruisers.

Re:Crystal: Fast as C, Slick as Ruby by imtringued on Thursday August 04, 2016 @08:53AM (#12225141)
In those situations you wouldn't even use malloc and simply allocate everything statically.
Re:Crystal: Fast as C, Slick as Ruby by rm445 on Thursday August 04, 2016 @04:08AM (#12224145)
Just as a point of interest, I believe there are special forms of garbage collector that are suitable for hard real time systems.

The principle is to regularly use a bounded amount of time for collecting - in line with the latency requirements for the whole system. I think the relevant term is 'tick tock', as in tick - compute, tock - collect.

Re:Crystal: Fast as C, Slick as Ruby by friendzis on Thursday August 04, 2016 @04:26AM (#12224214)
The thing about hard real time systems is that they must be predictable, which is quite wide term. Predictable memory utilization, predictable computation cost, predictable response time. In an attempt to at least fit into these requirements GC must be "passive", on-demand i.e. callable from code. Even with bounded collect times, number of collectings must be predictable/controlled to predict computational cost/time of code paths. And that becomes not much different from manual memory management.
Re:Crystal: Fast as C, Slick as Ruby by _pmf_ on Thursday August 04, 2016 @06:04AM (#12224504)
> Predictable memory utilization, predictable computation cost, predictable response time.

All of these can happen with non-GCd languages through heap fragmentation (i.e. even when correctly allocating and deallocating memory, you can still end up with a fragmented heap.) Tho only way to aviod this is to avoid all dynamic allocation (which is indeed done in a lot of systems) or exclusively use memory pools instead of a traditional heap.

Re:Crystal: Fast as C, Slick as Ruby by chaoxu on Thursday August 04, 2016 @05:33AM (#12224394)
If there is no need for predicting memory utilization, then doesn't real time GC fit the bill? Consider all your know w/e you want execute in time T. A real time GC make sure it always execute in time 2T. For any sequence of operations.
Re:Crystal: Fast as C, Slick as Ruby by Svenskunganka on Thursday August 04, 2016 @03:42AM (#12224041)
Ah, I see what you mean. Thank you for clarifying!
Re:Crystal: Fast as C, Slick as Ruby by bjourne on Thursday August 04, 2016 @01:01PM (#12226920)
Any program running on any non-realtime OS can stop for any number of milliseconds. There are a billion reasons for such interruptions like other processes wanting to run, cleanup phases internal to the OS, memory paging...

If your program stops for 50 ms, do you really care if it was because of a GC cycle or something else? If you really do care, then you are not allowed to target Linux, Windows or OS X all of which are decidedly not real time operating systems.