4 ms·
> This has a runtime cost. As does using a conservative/"very slow" GC. I'm sceptical, but it may be that D's situation means trading a pervasive slowness (if
by dbaupp 10y ago
> This has a runtime cost.
As does using a conservative/"very slow" GC. I'm sceptical, but it may be that D's situation means trading a pervasive slowness (if the parent is true, I don't know) for no write barriers is the right choice, differing to the conventional wisdom from other languages, but that's the argument you need to make, not just that write barriers are slow.
- atilaneves 10y agoThe slow GC is only a runtime cost if it ever runs. If no garbage is created in inner loops and stack allocation is preferred there's no reason it _has_ to run.
- p0nce 10y agoThe case against write barriers is pretty simple: the slowness of the GC can be workarounded, while memory barriers cannot. If they are needed, no other way to copy pointer values (which are quite pervasive in system programming).
- pcwalton 10y ago> The case against write barriers is pretty simple: the slowness of the GC can be workarounded, while memory barriers cannot. What workaround do you have in mind, and how does it not apply to write barriers?
- p0nce 10y agoYou can always use less of the GC, but there are no way not to use pointers. For example, I sell products in D which disable the GC completely, I certainly don't want write barriers.
- pcwalton 10y agoIf you can safely disable the GC, then you can safely disable write barriers.
- p0nce 10y agoAnd if I use only a bit of the GC, can I use only a bit of write barriers? Walter Bright was right about segmented stacks, I'm tempted to think he's right about write barriers too.
- pcwalton 10y agoIf the compiler can statically tell which pointers point to GC memory (something it usually needs to know anyway), yes.
- p0nce 10y agoIn D this is indeed known only at runtime, one of the decision was that "there should be only one type of pointers". immutable(T) doesn't guarantee it isn't in the GC heap from what I can gather. shared(T) could perhaps do it, but it's rather unpopular.
- pcwalton 10y agoIf you really don't know until runtime what heap a pointer is in, then write barriers will have some kind of cost, but it should be low (definitely not atomic). However, if you don't know statically what kind of heap a pointer is in, you're going to have a poorly performing GC system no matter what.