Skip to content

String index - #1784

Merged
karussell merged 20 commits into
masterfrom
string_index
Nov 14, 2019
Merged

karussell merged 20 commits into
masterfrom
string_index

Conversation

@karussell

@karussell karussell commented Nov 11, 2019 •

Copy link
Copy Markdown
Member

This PR introduces a flexible storage to store key-value String pairs for every edge and will replace the NameIndex, so that we can store translated name tags ala name_ru, ref-tags separately or even arbitrary tags per edge. (It is basically a Map ala Map<Long, Map<String, String>> except that you cannot define Long when you put it and get it returned when you add the Map<String, String>.)

This PR only introduces the index, we still need a method like edge.putExtra("key", "value") and we could also introduce a generic StringPathDetails and replace StreetNameDetails. Related also to #1772.

The index has the following limitations:

  • append-only storage. I.e. updating existing key-value pairs for one edge is only possible via allocating more space
  • supports up to 32768-1 unique keys (max length of each is 65k) and holds them in-memory
  • arbitrary values with a length of 255 bytes (UTF-8). Is mostly sufficient, also for names.
  • it does a simple duplicate detection to reduce storage size, but does this only for identical keys or identical values or fully equal entry maps (no partial strings)

TODOs:

  • the simpleCache brings 10% smaller size on disk but makes everything a bit more complicated
  • store ints even if it needs to be split over 2 segments => use get+setBytes (or use padding?)
  • is storing all tags already possible? Yes! How large does the index get => 221MB for Germany i.e. increases the total size by only 15% (5310 unique keys - make sure to exclude our artificial tags like estimated_center/distance and duration. Maybe also all tags that are already handled in our parsers)
  • compare speed for bigger and smaller maps - looks good
  • improve storage size further for larger maps like Germany. Trying to use lz4-java failed and even increased the size for the compressed data. But a very interesting tool is zstd that can be trained to specific data which would be likely beneficial for OSM data. A similar tool is http://ed-von-schleck.github.io/shoco/ but for now we'll keep every as it is.

@otbutz

otbutz commented Nov 11, 2019

Copy link
Copy Markdown
Contributor

Looks good 👍

We could use this to store countrycodes per edge like i proposed it in #1709

@karussell

Copy link
Copy Markdown
Member Author

Thanks! Works indeed surprisingly well.

We could use this to store countrycodes per edge like i proposed it in #1709

In general this is more for the path extraction phase or for the MVT endpoint. It is not really suited for routing due to its design towards more compact size e.g. loops through all values of one edge. I'm sure for smaller areas it is still possible to do that, but this shouldn't be promoted in the core and should be done via EncodedValues instead.

@otbutz

otbutz commented Nov 11, 2019

Copy link
Copy Markdown
Contributor

In general this is more for the path extraction phase or for the MVT endpoint.

That's exactly my use case as I would like to add country information to the path details. The StringIndex would allow me to do this fairly cheap and i could avoid adding ~250 countries to the Country enum to get global coverage. Storing all this information in the graph would require roughly one byte per edge which seems like a waste of space considering that we currently ship just a few SpatialRule implementations.

@karussell

karussell commented Nov 12, 2019 •

Copy link
Copy Markdown
Member Author

That's exactly my use case as I would like to add country information to the path details.

Have a look into this branch: https://github.com/graphhopper/graphhopper/tree/getall_prototype

More a prototype (virtual edges won't work), but the rest seems to work fine and also for bigger areas:

image

You can even misuse this to store the OSM ID ... highly inefficient but oh well...

@michaz

michaz commented Nov 13, 2019

Copy link
Copy Markdown
Member

Thank you thank you thank you.

@karussell karussell added this to the 1.0 milestone Nov 14, 2019
@karussell
karussell merged commit 798ad4f into master Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants