Skip to content
Back to the collection

Biased reference counting

Jiho Choi, Thomas Shull, Josep Torrellas

2018 · Proceedings of the 27th International Conference on Parallel Architectures and Compilation Techniques

Read the paper
HN score
0
Mentions
6
Readers
5
Months
5
What’s in a score?

In the conversation

Original HN comments, with labels from simple text rules. A label describes the whole comment and may miss context or irony. Read the discussion to make up your own mind. About the labels

6 selected excerpts · 6 total mentions

Someone
Neutral mention · rule
In addition to what others said, even if counts have to be updated, that need not always use atomic operations. See https://dl.acm.org/doi/10.1145/3243176.3243195: “BRC is based on the observation that most objects are only accessed by a single thread, which allows most RC operations to be performed non-atomically. BRC leverages this by biasing each object towards a specific thread, and keeping two counters for each object --- one updated by the owner thread and another updated by the other threads. This allows the owner thread to perform RC operations non-atomically, while the other threads update the second counter atomically.“ (I don’t know whether Swift uses this at the moment)
throwaway313373
Neutral mention · rule
The most interesting idea in my opinion is biased reference counting [0]. An oversimplified explanation (and maybe wrong) of it goes like this: problem: - each object needs a reference counter, because of how memory management in Python works - we cannot modify ref counters concurrently because it will lead to incorrect results - we cannot make each ref counter atomic because atomic operations have too large performance overhead therefore, we need GIL. Solution, proposed in [0]: - let's have two ref counters for each object, one is normal, another one is atomic - normal ref counter counts references created from the same thread where the object was originally created,…
Read the full comment
atomic counts references from other threads - because of an empirical observation that objects are mostly accessed from the same thread that created them, it allows us to avoid paying atomic operations penalty most of the time Anyway, that's what I understood from the articles/papers. See my other comment [1] for the links to write-ups by people who actually know what they're talking about. [0] https://dl.acm.org/doi/10.1145/3243176.3243195 [1] https://news.ycombinator.com/item?id=42059605
malkia
Neutral mention · rule
Not sure what is currently in swift, but this paper described biased reference counting approach - e.g. in way two counters - one non-atomic to be used only by specific thread (supposed owner?), and another (atomic) by all other threads - so the sum of these two shows the real reference count (somewhat). Paper here - https://dl.acm.org/doi/pdf/10.1145/3243176.3243195 (Before reading the paper I was expecting that the additional bytes were put for the split counter, plus thread id - but it actually packs them using lower bits for reference counting). I wonder what abseil/folly/tbb do - need to check (we are heavy std::shared_ptr users, but I don't think 14 bits as described in the paper above would be enough for our use case)
NobleExpress
Neutral mention · rule
I've always heard of the "Swift elides reference counts" statements but I've never seen it substantiated. I don't claim to be a Swift GC expert by any means, but the impression I get from the two Swift GC papers I've read [1, 2] is that Swift has a very simple implementation of RC. The RC optimization document (albeit the document is incomplete) [3] also doesn't give me the impression that Swift is doing much eliding of reference counts (I'm sure it is doing it for simple cases). Do you have any links which might explain what kind of eliding Swift is doing? EDIT: The major RC optimizations I have seen which elide references are deferral and coalescing and I'm fairly certain that Swift is doing neither. [1]: https://dl.acm.org/doi/abs/10.1145/3170472.3133843 [2]: https://doi.org/10.1145/3243176.3243195 [3]: https://github.com/apple/swift/blob/main/docs/ARCOptimizatio...
Someone
Neutral mention · rule
> Swift's refcounting is atomic (as is objc's) Most of the time it’s possible to avoid atomic instructions and still be thread-safe. https://dl.acm.org/doi/10.1145/3243176.3243195: “BRC is based on the observation that most objects are only accessed by a single thread, which allows most RC operations to be performed non-atomically. BRC leverages this by biasing each object towards a specific thread, and keeping two counters for each object --- one updated by the owner thread and another updated by the other threads. This allows the owner thread to perform RC operations non-atomically, while the other threads update the second counter atomically. We implement BRC in the…
Read the full comment
Swift programming language runtime, and evaluate it with client and server programs. We find that BRC makes each RC operation more than twice faster in the common case. As a result, BRC reduces the average execution time of client programs by 22.5%, and boosts the average throughput of server programs by 7.3%.” I remember reading that this made it into Swift, but cannot find it, so I’m not sure anymore. And of course, the Swift compiler tries to avoid unnecessary refcount updates.

Keep following the thread.

More in Psychology

More from the same topics.

2018arXiv

Talent vs Luck: the role of randomness in success and failure

A. Pluchino. A. E. Biondo, A. Rapisarda

The largely dominant meritocratic paradigm of highly competitive Western cultures is rooted on the belief that success is due mainly, if not exclusively, to personal qualities such as talent, intelligence, skills, efforts or risk taking.

16 mentions14 months
2.5HN score