News for hackers. Stuff that matters.
Re:Swift 6 by timeon on Tuesday September 17, 2024 @05:26PM (#41572968)
> Swift does not use virtual machine and garbage collection, it competes more to c++ and rust

Doesn't it use ARC by default?

Re:Swift 6 by azinman2 on Tuesday September 17, 2024 @05:43PM (#41573162)
Which is reference counting, not garbage collection. Ref counts free when count = 0. Garbage collection scans all object pointers and looks for loops / no missing pointers.
Re:Swift 6 by mkl on Tuesday September 17, 2024 @06:04PM (#41573363)
That's tracing garbage collection. Reference counting is another type of garbage collection. https://en.wikipedia.org/wiki/Garbage_collection_(computer_s...
Re:Swift 6 by derrasterpunkt on Tuesday September 17, 2024 @07:04PM (#41573830)
Reference counting is not tracing garbage collection. To also quote a Wikipedia Link: „The main advantage of the reference counting over tracing garbage collection is that objects are reclaimed as soon as they can no longer be referenced, and in an incremental fashion, without long pauses for collection cycles and with clearly defined lifetime of every object.“

+ https://en.wikipedia.org/wiki/Reference_counting

Re:Swift 6 by mkl on Tuesday September 17, 2024 @09:35PM (#41574820)
Of course reference counting is not tracing garbage collection. I never said it was. The comment I replied to claimed reference counting was not garbage collection at all and seemed to think tracing garbage collection was the only kind of garbage collection. Reference counting and tracing garbage collection are two different types of garbage collection.
Re:Swift 6 by vor_ on Saturday September 28, 2024 @10:01AM (#41680272)
> Reference counting is not tracing garbage collection.

???

They didn't say it was.

Re:Swift 6 by vor_ on Saturday September 28, 2024 @10:01AM (#41680268)
Reference counting is a kind of garbage collection.
Re:Swift 6 by synergy20 on Tuesday September 17, 2024 @05:45PM (#41573185)
it does, I thought ARC is more performant than GC and has no stop-the-world issue,thus not a GC
Re:Swift 6 by pebal on Tuesday September 17, 2024 @06:11PM (#41573433)
ARC is a variation of GC. Besides, a tracing GC doesn't have to stop the world at all.
Re:Swift 6 by neonsunset on Tuesday September 17, 2024 @06:56PM (#41573764)
Usually, it's the other way around: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

binary-trees is almost completely dominated by the time spent in allocator code, and stresses its throughput. This benchmark showcases how big of a gap is between manual per-thread arenas, then tracing generational multi-heap GCs, then ARC and more specialized designs like Go GC. Honorable mention goes to BEAM which also showcases excellent throughput by having process-level independent GCs, in this case resembling the behavior of .NET's and OpenJDK GC implementations.

Re:Swift 6 by astrange on Tuesday September 17, 2024 @11:12PM (#41575394)
A tree is indeed a bad fit for RC; so is anything else where you have multiple references to something but know there is a single real owner.

I'd suggest keeping strong references to all the tree nodes in an array, then having everything within the tree be unowned. Basically fake arena allocation.

Actually, the way it's written:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

is a common way you see toy data structures code written, but it's inefficient (because pointer chasing is slow) and there's better patterns. If you use the arena method above, you could use indexes into the arena. If not, intrusive data structures (where the references are inside Node instead of inside Tree) are better.

Re:Swift 6 by neonsunset on Tuesday September 17, 2024 @11:25PM (#41575471)
Pointer chasing is irrelevant here. It takes <= 15% of the execution time, and CPUs have gotten good at it. If it takes more - it speaks more about the quality of the allocator which has poor memory locality. As noted in my previous comment, it is dominated by the time spent in the allocator/GC code.

Please read https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

The requirement to implement the same algorithm with the same data structure is what makes this benchmark interesting and informative. Don't tell me "allocate parent object A, allocate child objects C, D and E and assign them to A's fields, then allocate array F and G, and assign them to D's fields" isn't the bread and butter of all kinds of application logic, something that this benchmark stresses.

Re:Swift 6 by astrange on Tuesday September 17, 2024 @11:32PM (#41575504)
Some CPUs are good at it, but most aren't. (Apple's are.)

But that's not the actual issue; the issue is that pointers are big (8 bytes) and indexes are smaller, so now you can fit more in the cache. It would also help GC because it doesn't have to trace them.

Also, I don't recommend intrusive structures merely because they'd be better for language games. I think they're better in general ;)

Re:Swift 6 by neonsunset on Tuesday September 17, 2024 @11:37PM (#41575527)
> But that's not the actual issue; the issue is that pointers are big (8 bytes) and indexes are smaller, so now you can fit more in the cache. It would also help GC because it doesn't have to trace them.

Please read 'binary-trees' description and submission rules (#2). You are missing the point(er).