Repository navigation
Description
TL;DR
- good news is that there are definitely commonly used chinese characters that we can bundle together into special glyph PBFs.
- bad news is that this amounts to about ~3000-4000 characters which will amount to a ~2-3MB overhead and it's not likely we can reduce this overhead much.
- other good news is this approach will likely work for hangul (korean) which has similar size/range waste issues though not as bad as cjk.
Notes from weekend analysis (source committed here https://github.com/mapbox/fontserver/tree/char-spec/spec).
Background
- There are a lot of chinese characters -- "Chinese characters are theoretically an open set" -- and a modern dictionary puts the number in the 100,000+.
- The problem we're dealing with is pretty well discussed especially in relation to learning chinese. Most discussions put the "99%" use character count at around 3000-4000 chars (e.g. http://www.commonchinesecharacters.com/Lists/MostCommon2500ChineseCharacters).
Prep
- Sample of text that we need to render. In
spec/fixtures/I've added 12 z14 vector tiles of major chinese cities. - 4096 most frequent chinese characters, in all
nametags from OSM. This is dumped tocjk-osm.json. - 4096 most frequent chinese characters, from an academic analysis of modern chinese character frequency (http://lingua.mtsu.edu/chinese-computing/statistics/). This is dumped to
cjk-modern.json.
Approach
Assuming a character that falls into the 4096 most freq character use can be grabbed from a set of CJK common PBFs or so, we can analyze the range count for our 12 vector tiles:
none (78 ranges)
[ '0-255',
'19968-20223',
'20224-20479',
'20736-20991',
'20992-21247',
'21248-21503',
'21504-21759',
'21760-22015',
'22016-22271',
'22272-22527',
'22528-22783',
'22784-23039',
'23040-23295',
'23296-23551',
'23552-23807',
'23808-24063',
'24064-24319',
'24320-24575',
'24576-24831',
'24832-25087',
'25088-25343',
'25344-25599',
'256-511',
'25600-25855',
'25856-26111',
'26112-26367',
'26368-26623',
'26624-26879',
'26880-27135',
'27136-27391',
'27392-27647',
'27648-27903',
'27904-28159',
'28160-28415',
'28416-28671',
'28672-28927',
'28928-29183',
'29184-29439',
'29440-29695',
'29696-29951',
'29952-30207',
'30208-30463',
'30464-30719',
'30720-30975',
'30976-31231',
'31232-31487',
'31488-31743',
'31744-31999',
'32000-32255',
'32256-32511',
'32512-32767',
'32768-33023',
'33280-33535',
'33536-33791',
'33792-34047',
'34048-34303',
'34304-34559',
'34560-34815',
'34816-35071',
'35072-35327',
'35584-35839',
'35840-36095',
'36096-36351',
'36608-36863',
'36864-37119',
'37120-37375',
'37888-38143',
'38144-38399',
'38400-38655',
'38656-38911',
'38912-39167',
'39168-39423',
'39424-39679',
'39936-40191',
'40448-40703',
'40704-40959',
'8192-8447',
'8448-8703' ]
osm (26 ranges)
[ '0-255',
'20224-20479',
'20992-21247',
'256-511',
'28416-28671',
'29440-29695',
'29952-30207',
'33536-33791',
'38912-39167',
'8192-8447',
'8448-8703',
'cjk-common-0',
'cjk-common-1',
'cjk-common-10',
'cjk-common-11',
'cjk-common-12',
'cjk-common-13',
'cjk-common-14',
'cjk-common-2',
'cjk-common-3',
'cjk-common-4',
'cjk-common-5',
'cjk-common-6',
'cjk-common-7',
'cjk-common-8',
'cjk-common-9' ]
modern (34 ranges)
[ '0-255',
'22272-22527',
'256-511',
'26880-27135',
'27136-27391',
'27648-27903',
'27904-28159',
'28416-28671',
'29184-29439',
'29952-30207',
'30976-31231',
'32512-32767',
'33280-33535',
'33536-33791',
'34304-34559',
'39424-39679',
'8192-8447',
'8448-8703',
'cjk-common-0',
'cjk-common-1',
'cjk-common-10',
'cjk-common-11',
'cjk-common-12',
'cjk-common-13',
'cjk-common-14',
'cjk-common-15',
'cjk-common-2',
'cjk-common-3',
'cjk-common-4',
'cjk-common-5',
'cjk-common-6',
'cjk-common-7',
'cjk-common-8',
'cjk-common-9' ]
The scripts assume we split up the cjk-common PBF into chunks of 256. It looks like you will want most if not all of these 4096 characters as a baseline, always, all the time (if you run the script with 1 or 2 tiles alone you will often end up with 12-16 of the common ranges). You basically end up grabbing the common characters no matter what.
So combining the common glyphs into a single pack and eliminating the non cjk ranges from the list to reduce noise, we're down to:
osm (8 ranges)
[ '20224-20479',
'20992-21247',
'28416-28671',
'29440-29695',
'29952-30207',
'33536-33791',
'38912-39167',
'cjk-common' ]
modern (15 ranges)
[ '22272-22527',
'26880-27135',
'27136-27391',
'27648-27903',
'27904-28159',
'28416-28671',
'29184-29439',
'29952-30207',
'30976-31231',
'32512-32767',
'33280-33535',
'33536-33791',
'34304-34559',
'39424-39679',
'cjk-common' ]
Conclusion + questions
Overall having a cjk-common glyph that takes precedence if a character falls into a fixed list of n (I picked 4096 based on a few runs -- 3000 not enough, 5000 has diminishing returns) looks like a good approach. You'll have most commonly used characters loaded and cached and will fire off requests as normal for other ranges as you hit less common characters.
The discrepancy between OSM's top characters and other analysis' top characters is worth some study though. Note that once we set this list changing it is very painful. It will affect any implementations using these endpoints and likely means we need to spec and version any endpoints around this strictly.
- "Place language" differs from normal usage significantly in english, german, etc. This is likely (?) the case for Chinese as well and could lead to this discrepancy.
- OSM data quality in China is an unknown to me. Setting a list of character frequency list based on the current state of OSM could be a bad idea without some overall confidence in current OSM data in China being representative of Chinese-language maps as a whole and future OSM data/map data.
Next actions
- Similar analysis for Hangul
- Branch of fontserver that can generate a PBF from a charlist rather than a start/end range,
- Branch of llmr that uses a cjk charlist to request the common CJK PBF and fallback to normal range glyphs otherwise,
- Test IRL
- Consult/further research on chinese char freq questions
Activity
yhahn commentedon Jun 1, 2014
Added to the test above a first example of what happens when there are no common character range PBFs around (78 range requests).
Refactor to accept an array of character codes as input. Refs #36.
yhahn commentedon Jun 19, 2014
@mikemorris answering some of your questions:
we'll need to build separate common glyphs for korean and japanese?
From http://en.wikipedia.org/wiki/CJK_characters
Basically: Korean, Japanese writing systems often include chinese characters for kind of "old-school" writing, and then have their own character/alphabet systems for the majority of normal use. For example, in Korea newspaper headlines are often have some CJK characters, and then the article will be in the Hangul character set.
Ideally we do not need to build separate common CJK glyph range PBFs for other languages that use CJK. We would only need to do this if the frequency distribution of character usage in Korean or Japanese of CJK characters is very different from Chinese. Let's stick with a single set of common CJK for now.
Korean: Hangul
There is the separate issue of whether Korean Hangul (a very different character set and also very large portion of unicode) needs a common glyph freq analysis. It is a big character range in unicode (http://jrgraphix.net/r/Unicode/AC00-D7AF) though not nearly as huge as CJK:
I did a quick analysis of this using a seoul OSM extract and recall from the results that likely a 256-512 set of common glyphs would have a very good impact. I haven't run an analysis that covers North/South Korea and that is what I think would be the next step here.
*Japanese: Hiragana + Katakana
I am less familiar with Japanese but these are two charactersets that do not cause as many headaches as CJK/Hangul. http://jrgraphix.net/r/Unicode/3040-309F, http://jrgraphix.net/r/Unicode/30A0-30FF
mikemorris commentedon Jun 19, 2014
Emailed [email protected] asking for a Korea (North and South) sub region extract at http://download.geofabrik.de/asia.html, is this something @joto could help out with?
lxbarth commentedon Jun 19, 2014
@mikemorris - per chat, use the Overpass API to download extracts. You can create a download URL with bbox and curl it.
@ajashton says there's also http://overpass-turbo.eu/ where you can use the wizard to easily make complex queries, eg
place=city in "North Korea".mikemorris commentedon Jun 19, 2014
Thanks @lxbarth, got extracts of North Korea and South Korea to analyze now.
mikemorris commentedon Jun 20, 2014
http://extract.bbbike.org/ is another resource for creating extracts, recommended by the folks at geofabrik
mikemorris commentedon Jun 23, 2014
Per chat with @nickidlugash, should we possibly do another analysis for traditional Chinese characters used in Taiwan, Hong Kong and Macau?
yhahn commentedon Jun 23, 2014
Start by adding more tile fixtures for these areas to
and running analysis of what the request profile looks like using the existing common-cjk ranges. If these fare badly/worse than the current tests, then yes, I think you should look into finding out why.
mikemorris commentedon Jun 23, 2014
Committed results of a full analysis of North and South Korea. North Korea has very limited OSM coverage, but the entirety of glyphs in use ended up being just 445. It also appears that none of the glyphs in the Hangul Compatibility Jamo are used.
mikemorris commentedon Jun 23, 2014
Should we expand the OSM CJK common analysis to include all the CJK ranges?
mikemorris commentedon Jun 24, 2014
@yhahn These look significantly worse than mainland China to me, I think we'll be needing a
cjk-traditionalcommon set as well.mikemorris commentedon Jun 24, 2014
mikemorris commentedon Jun 25, 2014
Adding all Hangul Unicode ranges:
3 remaining items
mikemorris commentedon Jun 26, 2014
Best attempt so far at splitting
cjk-commonisn't all that impressive, feels like I'm just spinning wheels here and that even the best solution here is still incredibly fragile.In this test,
cjk-osmis built only from the China OSM extract, andcjk-extended-osmis built from China, Taiwan and Japan extracts deduped againstcjk-osm.cjk-combined-osmis the union ofcjk-osmandcjk-extended-osm.mikemorris commentedon Jun 26, 2014
Only real way to fix Taiwan is to not trim at all.
mikemorris commentedon Jun 26, 2014
Added test fixtures for Japan:
Interesting that there appear to be requests for characters in the High Surrogates and Low Surrogates ranges, which all appear as � to me.
mikemorris commentedon Aug 5, 2015
TypeKit went with "dynamic subsetsetting", allowing requests for any number and combination of glyphs rather than predefined blocks.
http://blog.typekit.com/2015/06/15/announcing-east-asian-web-font-support/
It also sounds like this was a really easy issue for them to solve:
kkaefer commentedon Aug 6, 2015
Super interesting read, thanks for posting!
huangyingjie commentedon Nov 4, 2016
hi @mikemorris , what about the recent schedule? It's in great request for me. And is there any way to take part in?
glzcc commentedon Dec 8, 2016
download the file,how use this file?
jayantchens commentedon Jun 22, 2017
@yhahn @mikemorris Thank you for your answer. Could you tell me the exact details? Developing webGL.js (javaScript) in web web pages?
jcary741 commentedon Oct 12, 2026
Closing as stale.