Skip to content

Optimize vector tiles by selecting the most common languages #948

Closed

Description

@Rub21

From, #679

Currently, vector tiles are configured to display all the languages listed in the languages.sql file, which includes approximately 411 languages. During a tile request, the SELECT query, adds these language parameters to search the hstore column in the database tables.

While this setup works, but querying such a large number of languages can sometimes slow down the tiler . I propose selecting only the most commonly used languages from the database to include in the vector tiles.

To achieve this, we can analyze data from Taginfo to identify the most frequently used languages or, at the very least, obtain recommendations for the most relevant languages.

e.g:

cc. @1ec5 @danrademacher

Activity

  1. danrademacher commented on Jan 9, 2025

    @danrademacher

    Certainly we should eliminate any language for which there are 0 objects. Is there a quick way to at least test for that?

  2. 1ec5 commented on Jan 12, 2025

    @1ec5
    Member

    Until we finish exposing localized labels to end users (#481), mappers have little incentive to add localized names, so we can’t place too much stock in usage figures yet. Roughly speaking, the top 100 name:*=* keys are heavily skewed toward European languages that have official language status.

    name:alq (Algonquin) was implemented in #679 (comment) because it’s documented on the wiki. Someone went through a long time ago documenting all the valid language codes that were being used in OSM, no matter how rare. Taginfo shows that OHM has a somewhat different language coverage distribution. Essentially, our focus on history means we have more coverage of classical and extinct languages than OSM, and we should expect to have more indigenous language coverage as time goes on. We want to support indigenous languages especially because of their rarity as minority languages.

    I think it would be OK to prune unused keys as a temporary performance optimization. However, long-term, we’ll need to figure out a more scalable solution for processing these language keys.

  3. Rub21 commented on Jan 13, 2025

    @Rub21
    MemberAuthor

    I wrote a small script to filter languages that exist in TagInfo. From the entire list in the file languages.sql, which contains 411 languages, I found 93 languages with names. However, I don’t think this is the best approach because I discovered other languages in TagInfo with a large number of objects that are not reflected in our current list. For example:

    So, I think the best approach is to list the languages from TagInfo to display the names in the vtiles. However, in some cases, the keys are a bit messy (with messy i men that names include dates, sone random string in some cases).e.g 👇 , but i think those can be filtered.

    image

  4. 1ec5 commented on Jan 13, 2025

    @1ec5
    Member

    name:zh_pinyin=* was deprecated several years ago in favor of name:zh-Latn-CN-pinyin=*, per the ISO standard. OSM has performed this cleanup but OHM hasn’t yet. iD only supports the standard code, not the deprecated one.

  5. Rub21 commented on Jan 14, 2025

    @Rub21
    MemberAuthor

    OSM has performed this cleanup but OHM hasn’t yet.

    With cleaning , Do you mean change all the objects that has name:zh_pinyin=* to name:zh-Latn-CN-pinyin=*` , cleaning that should posible and easy. do you think that should be done by the team or someone from the community?

  6. danrademacher commented on Jan 14, 2025

    @danrademacher

    @1ec5 to provide a regex for selecting valid language labels, and we can use that to select valid name keys.

    But what about the long tail of languages that happen once in the whole world.

  7. 1ec5 commented on Jan 14, 2025

    @1ec5
    Member

    cleaning that should posible and easy. do you think that should be done by the team or someone from the community?

    Doesn’t matter, feel free to make the change, or one of us can post in the forum to ask for help.

    a regex for selecting valid language labels, and we can use that to select valid name keys

    The regular expression implemented in Planetiler should be valid in PostgresQL, though it might need some modifications if you put it in a shell script, depending on the tool you use. Note that this regular expression is case-sensitive.

    /ref onthegomap/planetiler#147 onthegomap/planetiler#1115 onthegomap/planetiler#1117

  8. Rub21 commented on Jan 15, 2025

    @Rub21
    MemberAuthor

    @1ec5 The Regex "^name:[a-z]{2,3}(-[A-Z][a-z]{3})?([-_](x-)?[a-z]{2,})?(-([A-Z]{2}|\\d{3}))?$" works very well, I was eable to filter the followinf number of languages:

    • 431 languages were filtered for the vector-tiler, each having at least 1 object (node, way, or relation).
    • 264 languages were filtered for the vector-tiler, each having at least 5 object (node, way, or relation).
    • 214 languages were filtered for the vector-tiler, each having at least 10 object (node, way, or relation).
    • 120 languages were filtered for the vector-tiler, each having at least 50 object (node, way, or relation).
    • 94 languages were filtered for the vector-tiler, each having at least 100 object (node, way, or relation).

    I think we can consider the 120 languages where the minimum number of objects required to appear is more than 50. Even 10 might work, but 1 seems too detailed.

  9. 1ec5 commented on Jan 15, 2025

    @1ec5
    Member

    For now, a threshold of 50 may be necessary, but I think we would indeed want to eventually support languages with fewer features, if only because some regionally significant indigenous languages don’t have many features in the native name. I’d also expect ancient languages such as Sumerian and Phoenician to be represented by very few but very significant features. However, we can defer that consideration until we find an alternative solution that doesn’t incur a performance penalty per language. Once we implement bilingual labeling in #799, this will become somewhat less of an issue, because we’d once again expose many of these names via name=* anyways.

  10. Rub21 commented on Jan 15, 2025

    @Rub21
    MemberAuthor

    Nice, I have filtered with a threshold of 50 objects min to consider to display the language in the vtiles.

  11. 1ec5 commented on Jan 15, 2025

    @1ec5
    Member

    Did you apply the regular expression above? I still see the deprecated keys name:zh_pinyin, name:ja_rm, and name:ja_kana in https://github.com/OpenHistoricalMap/ohm-deploy/blob/5f04f959ce57be98f6075c9ca0e7f7b06dc426b0/images/tiler-server/config/languages.sql#L11.

    Edit: Oh, I see that’s technically allowed due to the _ in the regular expression. That was probably overlooked in Planetiler.

  12. Rub21 commented on Jan 16, 2025

    @Rub21
    MemberAuthor

    If the issue is with the underscore in names, since those are not considered valid, we can update the regex to something like:

    ^name:[a-z]{2,3}(-[A-Z][a-z]{3})?((-[a-z]{2,}|x-[a-z]{2,})(-[a-z]{2,})?)?(-([A-Z]{2}|\d{3}))?$ the result looks like 👉 https://gist.github.com/Rub21/6b955c7cc67e8aedbb11ab01e5a609d7

  13. 1ec5 commented on Jan 16, 2025

    @1ec5
    Member

    Yes, that looks fine to me. Besides, these are all codes for romanizations and transliterations, which are more appropriate for geocoding than for rendering.

  14. Rub21 commented on Jan 23, 2025

    @Rub21
    MemberAuthor

    According to this the languages is requesting from taginfo , we may need to run updates in the tiler query every month to retrieve the languages. Since we are currently evaluating the number of objects that have a name:* tag, we might also need to implement a mechanism to automatically request new languages. For now, I am going to close this ticket.

  15. added theissue type on Mar 16, 2025
  16. reopened this on Apr 21, 2025
  17. moved this from In Production to In Progress in OpenHistoricalMap Dev Planningon Apr 21, 2025
  18. Rub21 commented on Apr 23, 2025

    @Rub21
    MemberAuthor

    Currently, the fetcher for languages from Taginfo is running inside the tiler-server container. It executes every time before the Tegola server starts and pushes a file with the current languages used in vector tiles to the S3 Planet bucket: https://s3.amazonaws.com/planet.openhistoricalmap.org/vtiles_languages.json. This way, we can publicly access the current languages that we are considering in the vtiles.

  19. moved this from In Progress to Ready for Staging in OpenHistoricalMap Dev Planningon Apr 23, 2025
  20. moved this from Ready for Staging to In Production in OpenHistoricalMap Dev Planningon May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions