Swift at Apple: Migrating the TrueType hinting interpreter

127 pointsposted 5 hours ago
by DASD

57 Comments

pjmlp

5 hours ago

During the State of Platform keynote, on the subject of Swift adoption across macOS, several examples were given, not only TrueType engine.

RIS is happening across all OS levels, if the keynote is to be believed.

MBCook

2 hours ago

They’ve been doing it for years. I don’t remember how we first knew, but I know they’ve been using Swift in kernels for at least some of the other chips like the Secure Enclave or whatever.

I’m not sure exactly which. I assume it’s some of the code and not all. But it’s not new in the abstract.

That said I don’t think I’ve heard of it in the kernel of MacOS on the main processor. That may be new.

Either way this is certainly the most concrete announcement I remember them ever giving on this stuff.

commandersaki

26 minutes ago

I know internally they use an IPsec implementation written by Rust (I think in the iCloud infra). Heard this from an ex-Apple engineer Ben (forgot his last name) that did a wonderful presentation of Rust from first principles. He said that it was hard to get people in on Rust when most would argue for Swift.

Edit: This is the guy: https://rustcurious.com/course/

DASD

4 hours ago

Curious the direction of Webkit as there was a nebulous mention of select portions being rewritten from C++ to Swift. And yet, the new ECMAScript module (ESM) loader for Safari 27 is implemented in C++ (https://webkit.org/blog/17967/news-from-wwdc26-webkit-in-saf...).

pjmlp

4 hours ago

No idea, maybe the private parts of the code, Safari isn't open source, or is coming later.

In any case I would have liked to have more info during the deep dive sessions.

As it is, Meet with Apple on security (a 5h long event) had much more information.

hirvi74

3 hours ago

What does RIS stand for?

gyomu

3 hours ago

Rewrite in Swift

willXare

3 hours ago

So RIS is Apple’s version of RiiR, but with better fonts.

cwillu

7 minutes ago

s/better/blurrier/

thewebguyd

a minute ago

Careful, you’ll bring out all the “but it’s true to print media” people.

saagarjha

4 hours ago

Interesting that this is published under the MIT, rather than Apple’s more favorite Apache 2, license

JumpCrisscross

4 hours ago

Why is it interesting?

drob518

4 hours ago

Presumably because MIT is even more permissive and it’s a change in Apple’s behavior.

favorited

3 hours ago

Some corporations prefer Apache 2.0 for projects where they'll be accepting contributions, because it includes patent protection and retaliation clauses. In case like this, where source code is just being published for reference and contributions aren't accepted, those risks don't exist.

zdw

3 hours ago

Given the age of TrueType, wouldn't nearly all patents be expired already?

Apache2's license I've heard described as mutually-assured-patent-destruction - if you use the code and make a patent claim, your rights to use the code go away.

So Apache2 offers little benefit here, and MIT may get it into more hands?

weinzierl

4 hours ago

Back in 2023 there was talks about Microsoft rewriting the font stuff in Rust for similar reasons Apple is now doing the Swift move.

I'm not sure what became of it and if it ever shipped. If anyone knows I'd be curious.

airstrike

4 hours ago

As much as I enjoyed Swift, one can only wonder what the world would look like if they had gone with Rust as their default language instead.

afavour

2 hours ago

One of the genius things about Swift is its interop with Objective C. Made the switch over considerably easier for developers. I’m not sure what that looks like in a Rust world.

Rust is also just a more complex language. I’m not convinced the benefits would have been worth it.

AceJohnny2

3 hours ago

Rust doesn't have an ABI [1]. Swift needed one to be a useable application language:

https://faultlore.com/blah/swift-abi/ (written by a core Rust developer)

[1] apart from the basic/universal C one, which prevents exposing any useful Rust semantics over the interface

jadengeller

4 hours ago

Modern Swift borrows a lot from Rust! And it also has its own benefits, both ergonomic and also supporting eg generic in dynamic libraries

ecshafer

3 hours ago

Swift and Rust were developed at similar times. I think of them more as having similar influences than borrowing from each other.

pohl

21 minutes ago

There’s no reason to invent your own head canon, the influence was openly acknowledged when Swift was new and it continues now that the language is developed out in the open (see Swift Ownership Manifesto)

est31

3 hours ago

Similar times and the Rust originator went on to work on Swift after it.

DenisChetwynd

3 hours ago

Graydon Hoare's impact on the language is marginal than that of Chris Lattner, the originator (also, Hoare joined the team much later)

airstrike

3 hours ago

These days I mainly write Rust but I did write a semi complex iOS app and enjoyed Swift. I just didn't love how slow the type checker was and how it got lost. I recall having to break things into smaller bits to help the compiler, and there were some oddities about the language.

The gap between the two languages is quite small, it just makes me wish Apple was also all-in on Rust

MBCook

2 hours ago

In the last year they’ve added improvements to the type checker to speed it up, those would have been released now.

They have further and much more significant changes that I think might have recently landed in the development version. That should make an even bigger difference. But it’s not in a released version yet.

And yes, none of us like that one part of Swift. Especially the DRASTIC difference compared to objective-C which really only checked syntax and little else.

It’s still probably my favorite language right now though I don’t get to write in it much.

DenisChetwynd

3 hours ago

maybe so on the surface, but it remains quite massive underneath; these languages are fundamentally different and target entirely different use cases

airstrike

42 minutes ago

I'm not sure Rust has one specific use case as its main goal, despite being immediately suitable for systems programming.

I use it for making user-facing desktop applications, to name one example.

vardump

3 hours ago

Does it borrow borrow checker?

tialaramex

2 hours ago

I believe Swift tends to use reference counting and copy-on-write strategies. This, like GC, is less for the programmer to think about and doesn't require the semantic checks, but sometimes the performance cost is unacceptable compared to what you'd write in Rust.

airspeedswift

2 hours ago

You can choose to use either refcounting or unique ownership for your types. For most use cases, refcounted (+ copy-on-write) is the best choice and is the default, but the truetype interpreter made extensive use of non-refcounted types to achieve this performance.

MBCook

2 hours ago

They have either recently added or talked about a borrow style system in the language as a way to avoid more copies and speed things up/lower memory usage/help with asynchronous programming.

anextio

2 hours ago

Yes, it has a borrow checker.

AndriyKunitsyn

3 hours ago

What's funny is from 2023 (I think), macOS just draws the UI unhinted. You have a 1080p display and you don't want to see the letters in the UI blurred to death? Tough luck, 1080p is incompatible with macOS, everybody needs "retina", and nobody cares that Windows and all Linux DEs look on 1080p just fine.

It looks like this hinter will be used only in rendering PDFs, because that's where they test the performance.

nomel

2 hours ago

My last 1080p monitor was around 20 years ago. I have trouble comprehending people still use them regularly.

AndriyKunitsyn

2 hours ago

People also use usable mice instead of touchpads, and they put the "ctrl" key where Apple thinks a useless "fn" should be. All kinds of things happen outside Apple world.

To me, it's more about what I'm used to. I have a perfectly fine several years-old monitor, so why should I throw it away?

mschuster91

2 hours ago

The problem is, as soon as you are not on a Mac but Linux or Windows, you are in for an awful, truly awful lot of pain. HiDPI support is a mess because even in the rare case applications are made with HiDPI in mind they are not tested on HiDPI machines.

Other way around, most Mac software is not tested how it behaves on inferior external monitors.

TazeTSchnitzel

2 hours ago

macOS has been drawing unhinted text for an eternity, and for those who can tolerate it on low-DPI screens, it's a great thing: the letter shapes look the same at all sizes, and the spacing between letters is consistent at all sizes.

bschwindHN

2 minutes ago

I'm a high DPI snob so I haven't used a low res monitor for work in forever, but isn't the entire point of font hinting to make the text more legible at smaller pixel grid sizes? Yes, of course the shapes are more consistent since the hinter isn't touching them, but isn't the end result just less legible text?

kbolino

2 hours ago

I had this problem on the first Apple Silicon Mac Mini in 2020 so it's at least a little older than 2023.

raphlinus

3 hours ago

Welcome to the club of doing high performance text in a memory safe language!

LoganDark

4 hours ago

I'm surprised the code has visible LLM smells. Though, I shouldn't be surprised. I hope the important bits are still human-controlled (and the same for Apple's many operating systems that absolutely deserve to remain stable and understood).

airspeedswift

4 hours ago

I assure you, every inch of the interpreter code has been stared at by humans, a lot. TBH even the assembly generated by it has.

dgellow

4 hours ago

From what I got Apple is using claude code A LOT internally

Cassell

3 hours ago

It would be interesting to see their internal guidance on LLM use. It’s a massive amount of new power that has to be wielded carefully. That kind of guidance might mean the survival or downfall of some big corps in the next few years.

wahnfrieden

4 hours ago

Yes they are using Claude Code - not the Xcode agents.

It worries me. I hope Codex adoption picks up there.

andrekandre

5 minutes ago

thats a shame if true, they really should be dog-fooding that horrible agent ui in xcode to bring it up to a usable state

troupo

4 hours ago

I think these are the types of things Apple should've focused on instead of half-heartedly barging ahead with SwiftUI and breaking the language in the process

saagarjha

4 hours ago

I mean they’re doing both

wg0

3 hours ago

No mention of AI? Hand written code?

numist

3 hours ago

There's mention at the end. The models (and Swift itself!) have evolved a lot since this project started, so the early code is largely hand-rolled and the later changes were mostly authored by centaurs (to steal a term from chess).

But I personally reviewed every line that shipped and was absolutely insufferable about testing.