Archive for September 27, 2017

Wednesday, September 27, 2017

Swift 4 Weak References

Mike Ash:

In the old implementation, Swift objects have two reference counts: a strong count and a weak count. When the strong count reaches zero while the weak count is still non-zero, the object is destroyed but its memory is not deallocated. This leaves a sort of zombie object sitting in memory, which the remaining weak references point to.

[…]

Swift’s new implementation of weak references brings with it the concept of side tables.

[…]

To avoid reserving eight bytes for the side table, Swift makes a nifty optimization. Initially, the first word of an object is the class, and the next word stores the reference counts. When an object needs a side table, that second word is repurposed to be a side table pointer instead. Since the object still needs reference counts, the reference counts are stored in the side table. The two cases are distinguished by setting a bit in this field that indicates whether it holds reference counts or a pointer to the side table.

The side table allows Swift to maintain the basic form of the old weak reference system while fixing its flaws. Instead of pointing to the object, as it used to work, weak references now point directly at the side table.

Previously: Weak and Unowned References in Swift, How Swift Implements Unowned and Weak References, Swift’s Lazy Weak References.

Update (2019-02-22): David Smith:

I’ve seen some confusion about this recently, so figure it’s worth discussing: unowned in Swift is not like __unsafe_unretained in ObjC, and actually is pretty odd.

The difference is just that unowned deterministically guarantees a crash if misused, but that requires a lot:

In particular:

• A second reference count for unowned references is kept

• The object’s deinit runs when all strong references are gone, but it isn’t actually freed until unowned ones are too!

(Yes, unowned references still pay for atomic math; unowned(unsafe) avoids that)

This fixes the most common bizarre symptom of over-releases in ObjC: my object deallocated and a new unrelated object reused its memory. Usually this showed up as “unrecognized selector xyz sent to object of type <completely the wrong type how did this get here>”.

Fixing Twitter With Reputation Systems

Chuq Von Rospach:

As someone who does community management for a living and uses Twitter as my primary social network, I see the problems on a daily basis, I see the friends of mine who have cut back their usage or given up entirely, and I find myself constantly self-editing my use of the service to stay away from topics I know are more likely to bring out the trolls, because Twitter simply doesn’t have the tools in place for me to protect myself if they arrive.

[…]

It’s clear to me they don’t know how to fix it, and that management really isn’t committed to wanting it fixed. Here’s one problem: Twitter uses how many accounts exist on the system and Monthly Active Users (MAU) as numbers used to judge the health of the company in their reports to the financial markets.

[…]

Twitter actually needs two reputation systems: one is tied to the identity of its users, and one is tied to the links that are used in postings to twitter. That latter one actually needs to go one level deeper, because the reputation should be built based on the final content the link points to, so that all links that end up pointing to the same source end up with the same reputation.

Chuq Von Rospach:

So, by using user actions (positive and negative) about a single tweet to generate a ranked listing of the tweets generating the largest negative response, we can bring that tweet to the notice of the abuse team, who can evaluate it. If they decide the tweet is abusive, they can delete it and that act will affect the reputations of everyone who interacted with that tweet. If the tweet includes a URL (and things like graphics have internal URLs so would be included in this) then that action can be rippled out to all tweets that include that URL or any URL that ultimately links to that content, and the same actions can be taken on all users interacting with all tweets that involve that URL. So the single administrative action can remove a problematic piece of content from the entire system with thoughtful systems design in tracking the content in the system.

[…]

Second, these systems will bias a system towards a reduced diversity of opinion because it will be biased by the reporting tendency of the larger sets of users. That’s inevitable and one reason to weight the abuse team decisions heavily is to give them influence to counter-act that. It should be noted that communities tend towards this reduced diversity over time with or without systems like this and I haven’t seen a reporting system designed yet that doesn’t introduce some bias against diversity, but it’s something to be aware of so that your management policies can try to minimize the bias. Echo chambers are inevitable, they seem to be human nature. I used to feel they needed to be actively discouraged, but these days, I’m not so sure that the fight is worth the effort and stress to the community. It’s a big subjective grey area.

Twitter:

Can’t fit your Tweet into 140 characters? 🤔

We’re trying something new with a small group, and increasing the character limit to 280!

Aliza Rosen and Ikuhiro Ihara:

Sometimes, I have to remove a word that conveys an important meaning or emotion, or I don’t send my Tweet at all. But when Iku Tweets in Japanese, he doesn’t have the same problem. He finishes sharing his thought and still has room to spare. This is because in languages like Japanese, Korean, and Chinese you can convey about double the amount of information in one character as you can in many other languages, like English, Spanish, Portuguese, or French.

Jack Dorsey:

This is a small change, but a big move for us. 140 was an arbitrary choice based on the 160 character SMS limit. Proud of how thoughtful the team has been in solving a real problem people have when trying to tweet. And at the same time maintaining our brevity, speed, and essence!

John Gruber:

I’d rather see them keep the limit at 140 characters but add support for plain text media attachments[…]

Given that Twitter is not profitable, I’m kind of surprised that longer tweets are a free feature. They could have added a paid tier with this and other advanced features.

Update (2017-10-04): Kurt Wagner:

Fast-forward 18 months, and Twitter finally did ship longer tweets, though with a much smaller character limit still in place than originally planned.

But that fear of straying too far from what was comfortable — and the protracted two-year timeline from product conception to launch — sums up Dorsey’s return as CEO of the company he founded, which happened exactly two years ago this Thursday. In that time, Twitter has survived, but it has failed to take big swings or move with the kind of urgency necessary of a company that’s fighting for its life.

YouTube Drops Echo Show, Amazon Adds Apple TV

Tim Hardwick:

Google pulled access to YouTube through Amazon’s display-based Echo Show smart speaker on Tuesday, a move that appears to have angered Amazon and led to conflicting public statements by both companies over the sudden move.

Joe Rossignol:

Nearly two years after Amazon stopped selling the Apple TV, a listing for the Apple TV 4K has been spotted on the website by 9to5Mac.

The Apple TV 4K is currently listed as out of stock, but the fact that it has been added back is fueling speculation that Amazon may be prepared to launch its Prime Video app on the tvOS App Store imminently.

When I checked just now, the Apple TV 4K was not available from Amazon.

Previously: Amazon Prime Video Coming to Apple TV.

Update (2017-09-28): See also: Hacker News.

Update (2017-09-29): Casey Newton (via John Gruber):

Google won’t tell Amazon why it blocked access to YouTube on its Echo Show device, Amazon’s senior vice president of devices and services said. Speaking to reporters at Amazon’s headquarters today, longtime Amazon exec Dave Limp said he would “send a team to Mountain View” tonight if Google would just specify what went wrong.

Update (2017-11-27): Tim Hardwick:

Google has seen fit to return YouTube to Amazon’s display-based Echo Show smart speaker, two months after the video service was pulled from the device.

iOS 11 Smart Punctuation and Null Characters

Gabriel Hauber:

iOS 11 + smart punctuation: two dashes = en-dash. Three dashes = en-dash + null-byte? Why?

Big problems with this and core data: if you store a string where user entered three dashes, the null byte causes early string termination.

Relicensing React, Jest, Flow, and Immutable.js

Matt Mullenweg:

A few weeks ago, Facebook announced they have decided to dig in on their patent clause addition to the React license, even after Apache had said it’s no longer allowed for Apache.org projects. In their words, removing the patent clause would “increase the amount of time and money we have to spend fighting meritless lawsuits.”

[…]

We had a many-thousand word announcement talking about how great React is and how we’re officially adopting it for WordPress, and encouraging plugins to do the same. I’ve been sitting on that post, hoping that the patent issue would be resolved in a way we were comfortable passing down to our users.

That post won’t be published, and instead I’m here to say that the Gutenberg team is going to take a step back and rewrite Gutenberg using a different library. It will likely delay Gutenberg at least a few weeks, and may push the release into next year.

Adam Wolff (Hacker News):

Next week, we are going to relicense our open source projects React, Jest, Flow, and Immutable.js under the MIT license. We’re relicensing these projects because React is the foundation of a broad ecosystem of open source software for the web, and we don’t want to hold back forward progress for nontechnical reasons.

This decision comes after several weeks of disappointment and uncertainty for our community. Although we still believe our BSD + Patents license provides some benefits to users of our projects, we acknowledge that we failed to decisively convince this community.

In the wake of uncertainty about our license, we know that many teams went through the process of selecting an alternative library to React. We’re sorry for the churn.

Matt Mullenweg:

I applaud Facebook for making this move, and I hope that patent clause use is re-examined across all their open source projects.