How does font caching / resources for each app work?

I'm a font developer. In the development process, I will revise a font and overwrite the OTF file that is currently enabled (registered) with macOS.

If I then launch an app, it will immediately use the revised version of the font; while apps that are already loaded will continue to use the old version.

This suggests that each app is loading new and separate font data, rather than getting it from some existing cache in memory. Yet macOS does have a "font cache" of some sort.

Some apps, like TextEdit, seem to only load the fonts that they need to use. However, other apps, like Pages, load every enabled (registered) font on the OS!! (According to the Open Files list in Activity Monitor.)

Given that /System/Library/Fonts/ is 625 Mb, and we can't disable any of it, isn't that a lot of data to be repeating? How many fonts is too many fonts?

I can't find much documentation about the process.

Is this still a mystery?

Sorry, just bumping this, in case anyone knows anything.

Maybe that's just the way Pages does it. Pages does have a font menu where the fonts are displayed in the appropriate typeface. TextEdit displays the font names using the system typeface. If you want to do anything fancy in TextEdit you have to use the system controls.

When I search for "font cache" on the Developer site, the only hit is this thread. So that suggests that the font cache, whatever it is or does, is an implementation detail.

I think perhaps those apps are just using fonts incorrectly. I guess I'm using them incorrectly too. What they're supposed to do is use fond descriptors for referencing fonts and then only create an actual font when they need it. If they did that then, maybe, they would get an updated font without relaunching.

Clearing the font cache using atsutil has been a thing for decades. So there is clearly some sort of font cache.

It seems to be a universal behaviour that any app will load the fonts it needs from the disk, and then keep them in memory. TextEdit does it, Affinity Designer does, Word does it. If apps are doing it wrong, they all are.

If I change the font file on disk, that new version will be used by any app that launches. Apps already running will continue to use their old copy in memory.

I could conceivably alter my font on disk before I launch every app I have, and every app would have a different version of that font.

This isn't a problem that needs fixing as such: I'm just curious how it's supposed to work.

If Apple is comfy with every app loading their own copy of all the font resources that they might need, rather than pointing to a single instance, then there we are.

Thanks for engaging with me.

Clearing the font cache using atsutil has been a thing for decades. So there is clearly some sort of font cache.

I never said there wasn't. I said it was an implementation detail. atsutil does have a "databases" command that will remove font database "along with any cache files".

It seems to be a universal behaviour that any app will load the fonts it needs from the disk, and then keep them in memory. TextEdit does it, Affinity Designer does, Word does it. If apps are doing it wrong, they all are.

I was just referencing something I noticed in the documentation during my search for information about font caches. I'm not going to use font descriptors like that. Apparently no one else does either. And there's no guarantee that it would change anything anyway.

That's why something that's an "implementation detail" is such a big deal and shouldn't be touched. Even the things that Apple documents and recommends are often impractical and frequently flat-out wrong.

If I change the font file on disk, that new version will be used by any app that launches. Apps already running will continue to use their old copy in memory.

Now that's behaviour that has been around for decades.

I'm just curious how it's supposed to work.

Apple never documents system behaviour to this level of detail. Modifying fonts is real 1990s kind of behaviour. I can't see it undergoing any significant change in expected user behaviour at this point.

If Apple is comfy with every app loading their own copy of all the font resources that they might need, rather than pointing to a single instance, then there we are.

You're talking about two different Apple apps, and possibly 3rd party apps. How Apple choses to implement its apps is Apple's decision to make and they aren't going to explain it in any way.

But this is a developer forum for people writing their own apps. Personally, I wouldn't be concerned with users changing fonts while my app is running. If any complain, I'll tell them not to do that. I'm also not going to use font descriptors everywhere. The only time I use them now is to get around limitations and partial implementations in other font APIs like NSFont. There's no way I would ever try to support fonts changing at runtime. No way - no how.

How does font caching / resources for each app work?
 
 
Q