servo / font-kit

A cross-platform font loading library written in Rust
Apache License 2.0
685 stars 103 forks source link

CoreText: Faster OTC font loading #232

Open osiewicz opened 8 months ago

osiewicz commented 8 months ago

Background: At Zed we've had users report that certain fonts could take a long time to load (https://github.com/zed-industries/zed/issues/6205). Admittedly these font files are quite big (Iosevka font weights like 300Mb), but I've still went looking and found out that font-kit might sometimes copy excessive amount of memory, as seen in the flamegraph of loading of Iosevka: image

This commit does several things:

The latter two changes are there so that you don't have to go through the font loading code just to get a font/just to match it. In order to initialize a Handle a font is loaded, but that Font is discarded (and needlessly loaded later) on current master. Note that I've pulled this commit verbatim from how we're using it in Zed; I made sure tests pass on Windows/Linux CI, but I didn't test on these platforms (as we're only available on Mac for now). The macOS part works fine on production for few days already.

Another reason to have that commit (I guess) is that it vastly improves throughput of examples like list-fonts and match-font (https://github.com/servo/font-kit/issues/209). The particular command-line that this user was using runs 10x faster for me with this commit (0.15s vs 1.1s on M1 Max). list-fonts completes in ~2s on debug build (vs not completing within 10s or so on current master).

osiewicz commented 5 months ago

Hey, is there anything I can do to push this PR forward?