Nim's new cycle collector

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 30 14:39:33 UTC 2020


On 4/30/20 10:05 AM, Araq wrote:
> On Thursday, 30 April 2020 at 13:49:54 UTC, Bienlein wrote:
>> Objective-C and Swift are two well-known languages that use reference 
>> counting. I remember some benchmark someone made in his thesis where 
>> he wrote a drive for something in various languages including Go and 
>> Objective-C.
>>
>> The version in Objective-C was too slow for the requirements of a 
>> driver. It turned out that changing counters when adding and removing 
>> items to collections were the main reason for this.
>>
>> On the contrary, the version in Go was fast enough. Apparently because 
>> Go's GC runs short enough on every collection invocation not to slow 
>> down the application too much.
>>
>> So to me the question arises whether reference counting in Nim could 
>> be a problem for a language that is also intended to be used for 
>> system programming. Eventually, a mix of reference counting and manual 
>> memory management would do.
> 
> 
> We don't do atomic reference counting so the results of Swift don't 
> apply. If you can scroll up to the beginning of 
> https://forum.nim-lang.org/t/5734 you can read more about it.

The key to performant reference counting I think is to have the compiler 
elide pairs of increments and decrements that it can determine are 
unnecesary, which is how Objective-C was able to get away with 
reasonable performance, even on old iPhones (though ARC wasn't available 
until iOS 5).

And I think Nim is doing that from what I read, correct? It's definitely 
a good model to look at for D.

-Steve


More information about the Digitalmars-d mailing list