* [subset] Keep hinting for fonts that require it Some legacy fonts have hinting programs that must be run for correct rendering; dropping them changes glyph advances and outlines. FreeType refuses to load these fonts without hinting, so do the same in the subsetter by ignoring HB_SUBSET_FLAGS_NO_HINTING for them. Only TrueType-outline fonts qualify. Identify them by family name, and by the length and checksum of their cvt, fpgm, and prep tables. The lists and the name-to-ASCII semantics are ported from FreeType's src/truetype/ttobjs.c; fontations has the same logic in read-fonts/src/tables/glyf/hint_reliant.rs. Keep the detection in hb-subset-hinting.hh rather than the subsetter, and add tests for both paths. Assisted-by: DeepSeek * [subset] Refine hint-dependent font detection - Store family names in a fixed-size table to avoid relocations. - Read the name table directly instead of building the name accelerator, and select the record with FreeType's platform and language priority. - Use hb_vector_t::set_storage() for the name buffer; treat an allocation failure as a non-match. - Pick the family name the way FreeType does: honor the OS/2 WWS bit, and do not fall through to a lower-priority family name when the preferred one exists but does not match. - Add equality operators and use CheckSum::set_for_data() for table checksums, rejecting unaligned data and handling the trailing bytes. - Use face->table.glyf and drop the beyond-64K guard. - Use ISALPHA/TOUPPER for the PDF randomization tag check. - Add a regression test for the OS/2 WWS family selection. Assisted-by: DeepSeek * [perf] Add NO_HINTING subset benchmarks Add a per-test NO_HINTING flag and enable it for the static TrueType font benchmarks, so subsetting through the hint-dependent-font detection path is measured. Benchmark names get a /nohinting suffix. Assisted-by: DeepSeek * [subset] Allow unaligned and unpadded checksum data CalcTableChecksum() can add a trailing partial word. Use that so _table_checksum() can pass arbitrary table data directly to CheckSum::set_for_data() instead of rejecting unaligned data and splitting off the padded prefix. Add unit coverage for padded, unpadded, and unaligned data. Assisted-by: DeepSeek * [subset] Rename and cache the hint-dependent face check Prefix the entry point with _hb_subset, and cache the answer in face user data so repeated subsetting of the same face does not repeat the name and table scans. Assisted-by: DeepSeek * [subset] Avoid allocating for the hint-dependent cache Store the hint_dependent_cache_t value in the face user-data pointer instead of allocating a bool. UNCACHED is zero, CACHED_FALSE is one, and CACHED_TRUE is two. Assisted-by: DeepSeek * [test] Validate checksums against Python-generated vectors Generate deterministic buffers and expected OpenType checksums with an independent Python implementation, covering unaligned offsets and lengths that are not multiples of four. The generator is committed as src/generate-checksum-vectors.py and rewrites the marked block in the unit test. Assisted-by: DeepSeek * [test] Drop the checksum vector generator Keep the Python-generated vectors embedded in test-checksum.cc, but remove the generator script and its markers. The comment records that the values were generated independently with Python. Assisted-by: DeepSeek * [subset] Use CheckSum::CalcTableChecksum directly Drop the trivial _table_checksum() wrapper and call CheckSum::CalcTableChecksum() from the table-ID builder. Assisted-by: DeepSeek * [subset] Release the sanitized name table hb_blob_ptr_t does not destroy its blob in its destructor, so add a scope guard to release it on every return path. Assisted-by: DeepSeek * [subset] Limit cache enum scope * [subset] Use dagger iteration for hint lists Replace the family-name and font-ID membership loops with hb_iter/hb_map/hb_any, and name the family-name capacity used by the table and its iterator. Assisted-by: DeepSeek
Building and Running
Benchmarks are implemented using Google Benchmark.
To build the benchmarks in this directory you need to set the benchmark option while configuring the build with meson:
meson build -Dbenchmark=enabled --buildtype=debugoptimized
The default build type is debugoptimized, which is good enough for
benchmarking, but you can also get the fastest mode with release
build type:
meson build -Dbenchmark=enabled --buildtype=release
You should, of course, enable features you want to benchmark, like
-Dfreetype, -Dfontations, -Dcoretext, etc.
Then build a specific benchmark binaries with ninja, eg.:
ninja -Cbuild perf/benchmark-set
or just build the whole project:
ninja -Cbuild
Finally, to run one of the benchmarks:
./build/perf/benchmark-set
It's possible to filter the benchmarks being run and customize the output via flags to the benchmark binary. See the Google Benchmark User Guide for more details.
The most useful benchmark is benchmark-font. You can provide custom fonts to it too.
For example, to run only the "paint" benchmarks, against a given font, you can do:
./build/perf/benchmark-font NotoColorEmoji-Regular.ttf --benchmark_filter="paint"
Some useful options are: --benchmark_repetitions=5 to run the benchmark 5 times,
--benchmark_min_time=.1s to run the benchmark for at least .1 seconds (defaults
to .5s), and --benchmark_filter=... to filter the benchmarks by regular expression.
To compare before/after benchmarks, you need to save the benchmark results in files
for both runs. Use --benchmark_out=results.json to output the results in JSON format.
Then you can use:
./subprojects/benchmark-1.8.4/tools/compare.py benchmarks before.json after.json
Substitute your version of benchmark instead of 1.8.4.
Profiling
If you like to disable optimizations and enable frame pointers for better profiling output, you can do so with the following meson command:
CXXFLAGS="-fno-omit-frame-pointer" meson --reconfigure build -Dbenchmark=enabled --buildtype=debug
ninja -Cbuild
However, this will slow down the benchmarks significantly and might give you inaccurate
information as to where to optimize. It's better to profile the debugoptimized build (the default).
Then run the benchmark with perf:
perf record -g build/perf/benchmark-subset --benchmark_filter="BM_subset_codepoints/subset_notocjk/100000" --benchmark_repetitions=5
You probably want to filter to a specific benchmark of interest and set the number of repititions high enough to get a good sampling of profile data.
Finally view the profile with:
perf report
Another useful perf tool is the perf stat command, which can give you a quick overview
of the performance of a benchmark, as well as stalled cycles, cache misses, and mispredicted branches.