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:
This commit does several things:
It uses native API to handle OTC via font descriptors. This gets rid of most of memmoves/memcopies
It permits storing an already loaded font in Handle to avoid loading it in load again.
It exposes matching module in public interface of a crate so that users don't have to go through Source::select_best_match`.
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).
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:
This commit does several things:
load
again.matching
module in public interface of a crate so that users don't have to go through Source::select_best_match`.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
andmatch-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).