1# Introduction 2 3Subset preprocessing is a mechanism which can significantly speed up font subsetting operations. 4It works by prepopulating datastructures from the source font which can be used in later subsetting 5operations to more quickly produce the subset. Preprocessing is useful in cases where multiple subsets 6will be cut from the same source font. 7 8# Usage 9 10```c++ 11hb_face_t* preprocessed = hb_subset_preprocess (source_face); 12 13... 14 15hb_face_t* subset = hb_subset_or_fail (preprocessed, subset_input); 16``` 17 18# Additional Details 19 20* A subset produced from a preprocessed face should be identical to a subset produced from only the 21 original face. The preprocessor does not change the functionality of the subsetter, just speeds 22 things up. 23 24* The preprocessing operation may take longer than the time it takes to produce a subset from the 25 source font. Thus the main performance gains are made when a preprocessed face is reused for 26 multiple subsetting operations. 27 28* Currently the largest performance gains are seen when using a preprocessed face for CFF subsetting. 29 30* The preprocessed face may contain references to the memory backing the source face. If this memory 31 is fully owned by a harfbuzz hb_blob_t* then it will automatically be kept alive for the lifetime 32 of the preprocessed face. However, if this memory is not fully owned by a harfbuzz hb_blob_t* then 33 it is necessary to ensure that the memory is kept alive for the lifetime of the preprocessed face. 34 35 36# Performance Improvements 37 38Here is the performance difference of producing a subset with a preprocessed face vs producing 39a subset with the source face: 40 41Benchmark | Delta Time (%) 42----------|----------------- 43BM_subset/subset_glyphs/Roboto-Regular.ttf/10_median|-56% 44BM_subset/subset_glyphs/Roboto-Regular.ttf/64_median|-33% 45BM_subset/subset_glyphs/Roboto-Regular.ttf/512_median|-28% 46BM_subset/subset_glyphs/Roboto-Regular.ttf/1000_median|-11% 47BM_subset/subset_glyphs/Roboto-Regular.ttf/nohinting/10_median|-56% 48BM_subset/subset_glyphs/Roboto-Regular.ttf/nohinting/64_median|-33% 49BM_subset/subset_glyphs/Roboto-Regular.ttf/nohinting/512_median|-21% 50BM_subset/subset_glyphs/Roboto-Regular.ttf/nohinting/1000_median|-9% 51BM_subset/subset_glyphs/Amiri-Regular.ttf/10_median|-67% 52BM_subset/subset_glyphs/Amiri-Regular.ttf/64_median|-48% 53BM_subset/subset_glyphs/Amiri-Regular.ttf/512_median|-21% 54BM_subset/subset_glyphs/Amiri-Regular.ttf/4096_median|-9% 55BM_subset/subset_glyphs/Amiri-Regular.ttf/nohinting/10_median|-66% 56BM_subset/subset_glyphs/Amiri-Regular.ttf/nohinting/64_median|-50% 57BM_subset/subset_glyphs/Amiri-Regular.ttf/nohinting/512_median|-8% 58BM_subset/subset_glyphs/Amiri-Regular.ttf/nohinting/4096_median|-9% 59BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/10_median|-85% 60BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/64_median|-71% 61BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/512_median|-3% 62BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/1400_median|4% 63BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/nohinting/10_median|-84% 64BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/nohinting/64_median|-72% 65BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/nohinting/512_median|0% 66BM_subset/subset_glyphs/NotoNastaliqUrdu-Regular.ttf/nohinting/1400_median|0% 67BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/10_median|-30% 68BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/64_median|-24% 69BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/512_median|-3% 70BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/1000_median|-3% 71BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/nohinting/10_median|-30% 72BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/nohinting/64_median|-24% 73BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/nohinting/512_median|-3% 74BM_subset/subset_glyphs/NotoSansDevanagari-Regular.ttf/nohinting/1000_median|-5% 75BM_subset/subset_glyphs/Mplus1p-Regular.ttf/10_median|-96% 76BM_subset/subset_glyphs/Mplus1p-Regular.ttf/64_median|-90% 77BM_subset/subset_glyphs/Mplus1p-Regular.ttf/512_median|-74% 78BM_subset/subset_glyphs/Mplus1p-Regular.ttf/4096_median|-25% 79BM_subset/subset_glyphs/Mplus1p-Regular.ttf/10000_median|-23% 80BM_subset/subset_glyphs/Mplus1p-Regular.ttf/nohinting/10_median|-95% 81BM_subset/subset_glyphs/Mplus1p-Regular.ttf/nohinting/64_median|-90% 82BM_subset/subset_glyphs/Mplus1p-Regular.ttf/nohinting/512_median|-73% 83BM_subset/subset_glyphs/Mplus1p-Regular.ttf/nohinting/4096_median|-24% 84BM_subset/subset_glyphs/Mplus1p-Regular.ttf/nohinting/10000_median|-11% 85BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/10_median|-84% 86BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/64_median|-77% 87BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/512_median|-70% 88BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/4096_median|-80% 89BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/10000_median|-86% 90BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/nohinting/10_median|-84% 91BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/nohinting/64_median|-78% 92BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/nohinting/512_median|-71% 93BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/nohinting/4096_median|-86% 94BM_subset/subset_glyphs/SourceHanSans-Regular_subset.otf/nohinting/10000_median|-88% 95BM_subset/subset_glyphs/SourceSansPro-Regular.otf/10_median|-59% 96BM_subset/subset_glyphs/SourceSansPro-Regular.otf/64_median|-55% 97BM_subset/subset_glyphs/SourceSansPro-Regular.otf/512_median|-67% 98BM_subset/subset_glyphs/SourceSansPro-Regular.otf/2000_median|-68% 99BM_subset/subset_glyphs/SourceSansPro-Regular.otf/nohinting/10_median|-60% 100BM_subset/subset_glyphs/SourceSansPro-Regular.otf/nohinting/64_median|-58% 101BM_subset/subset_glyphs/SourceSansPro-Regular.otf/nohinting/512_median|-72% 102BM_subset/subset_glyphs/SourceSansPro-Regular.otf/nohinting/2000_median|-71% 103BM_subset/subset_glyphs/AdobeVFPrototype.otf/10_median|-70% 104BM_subset/subset_glyphs/AdobeVFPrototype.otf/64_median|-64% 105BM_subset/subset_glyphs/AdobeVFPrototype.otf/300_median|-73% 106BM_subset/subset_glyphs/AdobeVFPrototype.otf/nohinting/10_median|-71% 107BM_subset/subset_glyphs/AdobeVFPrototype.otf/nohinting/64_median|-68% 108BM_subset/subset_glyphs/AdobeVFPrototype.otf/nohinting/300_median|-72% 109BM_subset/subset_glyphs/MPLUS1-Variable.ttf/10_median|-90% 110BM_subset/subset_glyphs/MPLUS1-Variable.ttf/64_median|-82% 111BM_subset/subset_glyphs/MPLUS1-Variable.ttf/512_median|-31% 112BM_subset/subset_glyphs/MPLUS1-Variable.ttf/4096_median|-9% 113BM_subset/subset_glyphs/MPLUS1-Variable.ttf/6000_median|-22% 114BM_subset/subset_glyphs/MPLUS1-Variable.ttf/nohinting/10_median|-88% 115BM_subset/subset_glyphs/MPLUS1-Variable.ttf/nohinting/64_median|-83% 116BM_subset/subset_glyphs/MPLUS1-Variable.ttf/nohinting/512_median|-31% 117BM_subset/subset_glyphs/MPLUS1-Variable.ttf/nohinting/4096_median|-16% 118BM_subset/subset_glyphs/MPLUS1-Variable.ttf/nohinting/6000_median|-18% 119BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/10_median|-44% 120BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/64_median|-18% 121BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/512_median|-2% 122BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/900_median|-6% 123BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/nohinting/10_median|-45% 124BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/nohinting/64_median|-17% 125BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/nohinting/512_median|-15% 126BM_subset/subset_glyphs/RobotoFlex-Variable.ttf/nohinting/900_median|-3% 127BM_subset/subset_codepoints/Roboto-Regular.ttf/10_median|-20% 128BM_subset/subset_codepoints/Roboto-Regular.ttf/64_median|-16% 129BM_subset/subset_codepoints/Roboto-Regular.ttf/512_median|-12% 130BM_subset/subset_codepoints/Roboto-Regular.ttf/1000_median|-10% 131BM_subset/subset_codepoints/Roboto-Regular.ttf/nohinting/10_median|-24% 132BM_subset/subset_codepoints/Roboto-Regular.ttf/nohinting/64_median|-14% 133BM_subset/subset_codepoints/Roboto-Regular.ttf/nohinting/512_median|-15% 134BM_subset/subset_codepoints/Roboto-Regular.ttf/nohinting/1000_median|-9% 135BM_subset/subset_codepoints/Amiri-Regular.ttf/10_median|-51% 136BM_subset/subset_codepoints/Amiri-Regular.ttf/64_median|-37% 137BM_subset/subset_codepoints/Amiri-Regular.ttf/512_median|-12% 138BM_subset/subset_codepoints/Amiri-Regular.ttf/4096_median|-1% 139BM_subset/subset_codepoints/Amiri-Regular.ttf/nohinting/10_median|-49% 140BM_subset/subset_codepoints/Amiri-Regular.ttf/nohinting/64_median|-35% 141BM_subset/subset_codepoints/Amiri-Regular.ttf/nohinting/512_median|-6% 142BM_subset/subset_codepoints/Amiri-Regular.ttf/nohinting/4096_median|-1% 143BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/10_median|-82% 144BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/64_median|-9% 145BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/512_median|0% 146BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/1400_median|0% 147BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/nohinting/10_median|-82% 148BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/nohinting/64_median|-13% 149BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/nohinting/512_median|-3% 150BM_subset/subset_codepoints/NotoNastaliqUrdu-Regular.ttf/nohinting/1400_median|2% 151BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/10_median|-40% 152BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/64_median|-26% 153BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/512_median|-5% 154BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/1000_median|3% 155BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/nohinting/10_median|-43% 156BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/nohinting/64_median|-24% 157BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/nohinting/512_median|-2% 158BM_subset/subset_codepoints/NotoSansDevanagari-Regular.ttf/nohinting/1000_median|2% 159BM_subset/subset_codepoints/Mplus1p-Regular.ttf/10_median|-83% 160BM_subset/subset_codepoints/Mplus1p-Regular.ttf/64_median|-67% 161BM_subset/subset_codepoints/Mplus1p-Regular.ttf/512_median|-39% 162BM_subset/subset_codepoints/Mplus1p-Regular.ttf/4096_median|-20% 163BM_subset/subset_codepoints/Mplus1p-Regular.ttf/10000_median|-25% 164BM_subset/subset_codepoints/Mplus1p-Regular.ttf/nohinting/10_median|-83% 165BM_subset/subset_codepoints/Mplus1p-Regular.ttf/nohinting/64_median|-65% 166BM_subset/subset_codepoints/Mplus1p-Regular.ttf/nohinting/512_median|-42% 167BM_subset/subset_codepoints/Mplus1p-Regular.ttf/nohinting/4096_median|-34% 168BM_subset/subset_codepoints/Mplus1p-Regular.ttf/nohinting/10000_median|-21% 169BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/10_median|-69% 170BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/64_median|-69% 171BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/512_median|-70% 172BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/4096_median|-84% 173BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/10000_median|-83% 174BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/10_median|-71% 175BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/64_median|-68% 176BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/512_median|-70% 177BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/4096_median|-86% 178BM_subset/subset_codepoints/SourceHanSans-Regular_subset.otf/nohinting/10000_median|-88% 179BM_subset/subset_codepoints/SourceSansPro-Regular.otf/10_median|-45% 180BM_subset/subset_codepoints/SourceSansPro-Regular.otf/64_median|-48% 181BM_subset/subset_codepoints/SourceSansPro-Regular.otf/512_median|-57% 182BM_subset/subset_codepoints/SourceSansPro-Regular.otf/2000_median|-66% 183BM_subset/subset_codepoints/SourceSansPro-Regular.otf/nohinting/10_median|-43% 184BM_subset/subset_codepoints/SourceSansPro-Regular.otf/nohinting/64_median|-50% 185BM_subset/subset_codepoints/SourceSansPro-Regular.otf/nohinting/512_median|-63% 186BM_subset/subset_codepoints/SourceSansPro-Regular.otf/nohinting/2000_median|-72% 187BM_subset/subset_codepoints/AdobeVFPrototype.otf/10_median|-69% 188BM_subset/subset_codepoints/AdobeVFPrototype.otf/64_median|-66% 189BM_subset/subset_codepoints/AdobeVFPrototype.otf/300_median|-74% 190BM_subset/subset_codepoints/AdobeVFPrototype.otf/nohinting/10_median|-70% 191BM_subset/subset_codepoints/AdobeVFPrototype.otf/nohinting/64_median|-71% 192BM_subset/subset_codepoints/AdobeVFPrototype.otf/nohinting/300_median|-75% 193BM_subset/subset_codepoints/MPLUS1-Variable.ttf/10_median|-66% 194BM_subset/subset_codepoints/MPLUS1-Variable.ttf/64_median|-46% 195BM_subset/subset_codepoints/MPLUS1-Variable.ttf/512_median|-15% 196BM_subset/subset_codepoints/MPLUS1-Variable.ttf/4096_median|-5% 197BM_subset/subset_codepoints/MPLUS1-Variable.ttf/6000_median|-16% 198BM_subset/subset_codepoints/MPLUS1-Variable.ttf/nohinting/10_median|-66% 199BM_subset/subset_codepoints/MPLUS1-Variable.ttf/nohinting/64_median|-45% 200BM_subset/subset_codepoints/MPLUS1-Variable.ttf/nohinting/512_median|-14% 201BM_subset/subset_codepoints/MPLUS1-Variable.ttf/nohinting/4096_median|-11% 202BM_subset/subset_codepoints/MPLUS1-Variable.ttf/nohinting/6000_median|-27% 203BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/10_median|-38% 204BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/64_median|-9% 205BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/512_median|-3% 206BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/900_median|-16% 207BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/nohinting/10_median|-39% 208BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/nohinting/64_median|-12% 209BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/nohinting/512_median|-4% 210BM_subset/subset_codepoints/RobotoFlex-Variable.ttf/nohinting/900_median|-2% 211BM_subset/instance/MPLUS1-Variable.ttf/10_median|-68% 212BM_subset/instance/MPLUS1-Variable.ttf/64_median|-45% 213BM_subset/instance/MPLUS1-Variable.ttf/512_median|-18% 214BM_subset/instance/MPLUS1-Variable.ttf/4096_median|-2% 215BM_subset/instance/MPLUS1-Variable.ttf/6000_median|4% 216BM_subset/instance/MPLUS1-Variable.ttf/nohinting/10_median|-69% 217BM_subset/instance/MPLUS1-Variable.ttf/nohinting/64_median|-46% 218BM_subset/instance/MPLUS1-Variable.ttf/nohinting/512_median|-11% 219BM_subset/instance/MPLUS1-Variable.ttf/nohinting/4096_median|4% 220BM_subset/instance/MPLUS1-Variable.ttf/nohinting/6000_median|-5% 221BM_subset/instance/RobotoFlex-Variable.ttf/10_median|-34% 222BM_subset/instance/RobotoFlex-Variable.ttf/64_median|-12% 223BM_subset/instance/RobotoFlex-Variable.ttf/512_median|6% 224BM_subset/instance/RobotoFlex-Variable.ttf/900_median|-6% 225BM_subset/instance/RobotoFlex-Variable.ttf/nohinting/10_median|-33% 226BM_subset/instance/RobotoFlex-Variable.ttf/nohinting/64_median|-11% 227BM_subset/instance/RobotoFlex-Variable.ttf/nohinting/512_median|3% 228BM_subset/instance/RobotoFlex-Variable.ttf/nohinting/900_median|0% 229