❌

Normal view

Rewriting Apple’s TrueType Hinting Interpreter in Swift

12 June 2026 at 20:34

Scott Perry:

My team rewrote Apple’s TrueType hinting interpreter in Swift, ask me anything.

[…]

I feel like naming just one would be a disservices to all of the features that made this effort possible (C interop, generics, noncopyable/nonescapable types) but at the end of the day I think the star of the show was the optimizer; despite being faster than the code it replaced, the new code is super readable and that was only possible because the optimizer was able to completely eliminate all of our abstractions.

The new version is faster, but the main motivation was security concerns.

Dmitrii Kalianov:

Is hinting useful/being used in the days of hi-dpi displays? I was under impression that Apple switched to grayscale anti-aliasing and ditched hinting.

Scott Perry:

For the most part hinting isn’t really necessary anymore, but thanks to being Turing-complete it has been Hyrum’s law-ed by at least one CJK font that uses hinting to lay out strokes in its characters.

Alex Rosenberg:

There were three major TrueType implementations at Apple IIRC:

  • The original 68K one
  • A rewrite for Copland that lived with ATS/ATSUI after Copland was cancelled
  • iPhone shipped one derived from heavily-modified FreeType that was current until today

Scott Perry:

One of the axioms for this project was that I wanted my team to write the most boring code possible—nearly identical structurally to the code it was replacing, because to do otherwise would introduce binary compatibility risk. The other axiom was 100% test coverage for all new code as it landed, with the same units testing both interpreters.

Rosyna Keller:

Is the font parsing code itself still C++?

Scott Perry:

There is also a “Safe Font Parser” for WebKit in Lockdown Mode, but it supports a subset of all the myriad features provided by font formats.

Previously:

Update (2026-06-16): Scott Perry (Hacker News):

Font parsers process data from untrusted sources, making the TrueType hinting interpreter a security-critical attack surface. To make the format more resilient on Apple platforms, we rewrote its hinting interpreter from C to memory-safe Swift for the Fall 2025 releases. In addition to memory safety, we also improved performance: on average, our Swift interpreter runs 13% faster than the C interpreter it replaced.

[…]

Binary compatibility was crucial for this project to succeed: existing programs had to continue to function the same as they did before, effectively unaware that a new implementation was in place. This means not just interface compatibility but pixel-identical glyph rendering as well, relative to the C implementation.

[…]

To ensure correctness, we developed two test suites. The first was a unit test suite that can target both implementations, providing exhaustive (99.7%) code coverage for both. This suite is included with the open source release of the Swift interpreter.

Then, to represent real-world workloads, we used a fuzzer to minimize a corpus of 10 million PDF files down to 4,200 without any loss of code coverage.

[…]

Following WebKit’s Safer Swift Guidelines, the example below demonstrates how to wrap a bridged structure from C in a projection type that uses Ref for lifetime safety, brokers bounds-safe access to the underlying data, and returns idiomatic Swift types to its callers.

The interpreter source is on GitHub.

Marcin Krzyzanowski:

@_lifetime(copy code, copy twilightZone, copy glyphZone)

See also: Phillip Tennen’s Writing a TrueType font renderer (Hacker News).

Previously:

Key Factors Driving Sustainable Stormwater Management Success

18 July 2026 at 22:18

A new study in npj Urban Sustainability points to the practical levers that determine whether stormwater systems actually deliver long-term sustainability. As cities expand and rainfall extremes intensify, green and nature-based infrastructure has been promoted to capture runoff, reduce flooding, and protect water quality. But the research warns that success is not automatic: design decisions and operational realities can make or break performance.

The authors, Sun, Randrup, Blecken and colleagues, analyze what they call “decisive factors” governing sustainable stormwater management. Their central message is that the most visible features—such as bioswales, permeable surfaces, or detention basins—only work when supported by the right planning assumptions and measurable hydrological outcomes.

A key technical theme is how stormwater must be matched to system capacity under changing conditions. The study emphasizes that system sizing, soil or media properties, and infiltration or storage behavior strongly influence whether the infrastructure can handle typical storms and rare, high-intensity events. When these factors are misestimated, treatment efficiency can collapse during peak flows.

Equally important are maintenance and lifecycle considerations. Sustainable stormwater is sensitive to clogging, sediment accumulation, vegetation health, and changes in catchment behavior. The research highlights the need for maintenance regimes that reflect likely failure modes, rather than generic schedules that ignore local hydrology and traffic or land-use impacts.

The paper also stresses the value of monitoring and model-informed decision-making. Reliable data on rainfall patterns, runoff routing, and pollutant loads allow managers to validate performance and adjust operations. This feedback loop helps prevent long-term degradation that otherwise remains invisible until issues become costly.

For cities seeking viral, widely transferable “what works” guidance, the authors’ findings offer a shortlist of priorities: realistic capacity planning, robust material characterization, design for multi-storm performance, and maintenance strategies tied to specific mechanisms. Together, these elements translate sustainability goals into systems that function under real weather and real urban change.

The study’s DOI is 10.1038/s42949-026-00448-4.

Subject of Research: Sustainable stormwater management / urban sustainability
Article Title: Decisive factors in sustainable stormwater management
Article References: Sun, Z., Randrup, T.B., Blecken, GT. et al. Decisive factors in sustainable stormwater management. npj Urban Sustain 6, 104 (2026). https://doi.org/10.1038/s42949-026-00448-4
Image Credits: AI Generated
DOI: https://doi.org/10.1038/s42949-026-00448-4

❌