Skip to content

MapDataStore enhance data retrieval #741

Closed

Description

@devemux86

From @ludwigb here:

My view would be only to extract rectangles (not any more complicated shapes, they could be implemented in user code as subsets of a envelope).

With the current MapFile format in mind, I think the best way is to have two operations:

  • read(BoundingBox bbox)
  • read(Set tiles) where the set of tiles is a contiguous set of tiles that covers a rectangular area

In general these would be two very different operations but for the MapFile format the first one must essentially be implemented through the second. With the internal structure of the MapFile there would be two different cases (which makes it tricky):

  • all tiles fall onto a single base tile (meaning actually the operation on the MapFile we currently have already reads all the right data, it just filters most tiles out)
  • the tiles span multiple base tiles: in this case multiple requests must be made and combined.
  • I vaguely remember that there was a third case, ???

Returning too much data is known to cause memory problems.....

The read(Set) operation could then be used in the LabelLayer to get all the labels for the tiles visible on screen....

Activity

  1. ludwigb commented on Dec 30, 2015

    @ludwigb
    Collaborator

    Commit 351f1d4 implements new retrieval functionality for the MapDataStore:

    • retrieval of POI data only
    • retrieval of Label data only. This includes POI data and all ways that have a name.

    Additionally, all retrieval methods can now also be called on a area of tiles defined by an upperLeft and lowerRight tile. I thought this is better than having a Set of Tiles, as it is clearer that the area is contiguous.

    By default, the implementations can simply combined retrieved data for an area of tiles or simply return all the data even though only POI or label data is required.

    However, the MapFile implementation utilizes the storage mechanism to read POI and label data based on MapFile blocks, thus reading a MapFile only once to retrieve the data for multiple tiles. This could possibly be optimized further if I really understood the underlying file format.

    These retrieval methods are used in the new implementation of a LabelLayer that does not cache the data from previous tile reads (less complexity, less memory overhead).

  2. devemux86 commented on Dec 30, 2015

    @devemux86
    CollaboratorAuthor

    Nice, will study the changes and start testing it.

  3. devemux86 commented on Dec 30, 2015

    @devemux86
    CollaboratorAuthor

    @ludwigb I see you use assert in non Test classes and in public methods.
    Shouldn't it be better to use usual checks with thrown exceptions instead?

  4. ludwigb commented on Dec 30, 2015

    @ludwigb
    Collaborator

    Should probably be removed.

    On 30 December 2015 at 12:35, Emux [email protected] wrote:

    @ludwigb https://github.com/ludwigb I see you use assert in non Test
    classes and in public methods.
    Shouldn't it be better to use the usual checks with thrown exceptions
    instead?

    —
    Reply to this email directly or view it on GitHub
    #741 (comment)
    .

  5. devemux86 commented on Dec 30, 2015

    @devemux86
    CollaboratorAuthor

    MapFile implementation is confusing me.
    We have readLabels which has redundant selector parameter, yet it's called also for poi data.

    (BTW methods sorting here would help better analysing the code)

  6. ludwigb commented on Dec 30, 2015

    @ludwigb
    Collaborator

    Well spotted, the naming is wrong and the method is duplicated. A hangover
    from a previous version, before I folded things together.

    Do we have an official ordering of methods? I usually shy away from
    reordering as it makes diffs even more difficult to understand, but it
    certainly does make sense here.

    On 30 December 2015 at 15:37, Emux [email protected] wrote:

    MapFile implementation is confusing me.
    We have readLabels

    private MapReadResult readLabels(Tile upperLeft, Tile lowerRight, Selector selector) {

    which has redundant 'selector' parameter, yet it's called also for poi data.

    (BTW a method sorting there would help too analysing the code)

    —
    Reply to this email directly or view it on GitHub
    #741 (comment)
    .

  7. devemux86 commented on Dec 31, 2015

    @devemux86
    CollaboratorAuthor

    As I dig deeper into the code, do you want me to make any changes or should I collect all my remarks and you'll review it afterwards?

    Do we have an official ordering of methods?

    We may have something in our IDE rules for contributors and I recall Thilo regularly did a code cleanup with sorting, etc.

    I usually shy away from reordering as it makes diffs even more difficult to understand

    I agree to that, we can just do it in separate commits with the usual label "no functionality change".

  8. applantation commented on Dec 31, 2015

    @applantation
    Collaborator

    I have been trying to get the Rearrange Code in Android Studio to actually
    do what I want, but just applied to the MapFile file. Not quite there yet.

    I will make the small changes you suggested cumulatively at one point,
    please continue with comments.

    Ludwig

    On 31 December 2015 at 08:18, Emux [email protected] wrote:

    As I dig deeper into the code, do you want me to make any changes or
    should I collect all my remarks and you'll review it afterwards?

    Do we have an official ordering of methods?

    We may have something in our IDE rules for contributors and I recall Thilo
    regularly did a code cleanup with sorting, etc.

    I usually shy away from reordering as it makes diffs even more difficult
    to understand

    I agree to that, we can just do it in separate commit with the usual label
    "no functionality change".

    —
    Reply to this email directly or view it on GitHub
    #741 (comment)
    .

  9. devemux86 commented on Dec 31, 2015

    @devemux86
    CollaboratorAuthor
    • In MapDataStore we have readLabels and readMapData methods doing the same thing. Do we actually need both of them (or required just for MapFile)?
    • In MapReadResult we could try improving deduplication performance by using interfaces of distinct elements (depending on interface use).

    Overall the map rendering appears less smooth now (compared to old LabelLayer). More tests are to be done for CPU / RAM performance.

  10. applantation commented on Dec 31, 2015

    @applantation
    Collaborator

    The default implementation of readLabels in MapDataStore does exactly the
    same thing as readMap data. It is just so that derived classes work without
    having to implement the interface. The recommendation is to provide a more
    efficient etc implementation for each derived class.

    My understanding was that the deduplicating uses the equals method on a
    class, so that would test (if implemented correctly) if the elements are
    different classes. Or what do you mean. (Reminder to self: check that in
    MapFile the deduplicating is not used, as there should be no duplicates).

    The MapDataStoreLabelStore retrieves new data if the underlying tile area
    has changed. So just with a bit of moving around there will not be a new
    retrieval, but when the tile area changes, then we have to retrieve the
    full data for all visible tiles again. That is a big hit on performance as
    the whole area will not be drawn until all data has been retrieved. This
    could be improved by making the retrieval asynchronous, i.e. drawing the
    data from the old set, while in a background thread retrieving the accurate
    data for the viewport, then refreshing when that new data is in.

    Ludwig

    On 31 December 2015 at 14:48, Emux [email protected] wrote:

    • In MapDataStore we have readLabels and readMapData methods doing the
      same thing. Do we actually need both of them (or required just for
      MapFile)?
    • In MapReadResult we could try improving deduplication performance by
      using interfaces of distinct elements (depending on interface use).

    Overall the map rendering appears less smooth now (compared to old
    LabelLayer). More tests are to be done for CPU / RAM performance.

    —
    Reply to this email directly or view it on GitHub
    #741 (comment)
    .

  11. devemux86 commented on Jan 1, 2016

    @devemux86
    CollaboratorAuthor

    Trying to integrate the new LabelLayer without success (though Samples seems working).
    Seeing random tiles without content and disappearing symbols / labels caused by many (Android):

    W/MapFile: invalid number of way nodes: 0
    W/MapFile: invalid number of way coordinate blocks: 0
    E/MapFile: length=153100; index=153100
    java.lang.ArrayIndexOutOfBoundsException: length=153100; index=153100
        at org.mapsforge.map.reader.ReadBuffer.readSignedInt(ReadBuffer.java:148)
        at org.mapsforge.map.reader.MapFile.decodeWayNodesSingleDelta(MapFile.java:368)
        at org.mapsforge.map.reader.MapFile.processWayDataBlock(MapFile.java:683)
        at org.mapsforge.map.reader.MapFile.processWays(MapFile.java:784)
        at org.mapsforge.map.reader.MapFile.processBlock(MapFile.java:452)
        at org.mapsforge.map.reader.MapFile.processBlocks(MapFile.java:544)
        at org.mapsforge.map.reader.MapFile.readMapData(MapFile.java:973)
        at org.mapsforge.map.reader.MapFile.readMapData(MapFile.java:831)
        at org.mapsforge.map.layer.renderer.DatabaseRenderer.executeJob(DatabaseRenderer.java:91)
        at org.mapsforge.map.layer.renderer.MapWorkerPool$MapWorker.run(MapWorkerPool.java:121)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:841)
  12. devemux86 commented on Jan 1, 2016

    @devemux86
    CollaboratorAuthor

    Also there are many (Java):

    org.mapsforge.map.reader.MapFile processWays
    WARNING: invalid way tag ID: 8300
    org.mapsforge.map.reader.MapFile processPOIs
    WARNING: invalid POI tag ID: 123
    org.mapsforge.map.reader.MapFile processWayDataBlock
    WARNING: invalid number of way coordinate blocks: 1060691
    org.mapsforge.map.reader.MapFile processBlock
    WARNING: invalid first way offset: 1078554
    org.mapsforge.map.layer.renderer.DatabaseRenderer executeJob
    WARNING: invalid longitude: 1004.0364423125
  13. ludwigb commented on Jan 1, 2016

    @ludwigb
    Collaborator

    Are you sharing a MapFile between the layers? Rather than opening a new
    file?

    The error actually comes from reading map data (not label data), so I
    assume what is happening is that two layers read from the same file
    descriptor, and thus move the same read position.

    The Samples app (I just checked) opens the same MapFile twice, so the read
    position is not shared.

    Ludwig

    On 1 January 2016 at 17:57, Emux [email protected] wrote:

    Also there are many like:

    org.mapsforge.map.reader.MapFile processWaysWARNING: invalid way tag ID: 8300org.mapsforge.map.reader.MapFile processPOIsWARNING: invalid POI tag ID: 123org.mapsforge.map.reader.MapFile processWayDataBlockWARNING: invalid number of way coordinate blocks: 1060691org.mapsforge.map.reader.MapFile processBlockWARNING: invalid first way offset: 1078554org.mapsforge.map.layer.renderer.DatabaseRenderer executeJobWARNING: invalid longitude: 1004.0364423125

    —
    Reply to this email directly or view it on GitHub
    #741 (comment)
    .

  14. devemux86 commented on Jan 2, 2016

    @devemux86
    CollaboratorAuthor

    Yes that was the cause, I used the same map data store in renderer and label store like in old days.

    Playing with it, I see occasionally (without visible artifacts):

    org.mapsforge.map.reader.MapFile processWayDataBlock
    WARNING: invalid number of way nodes: 0

    Also the CPU usage continues to be quite high.

  15. ludwigb commented on Jan 4, 2016

    @ludwigb
    Collaborator

    I pushed a bit of cleanup plus a bug fix that relates to retrieval for
    certain zoom ranges.

    I think re speed we have the following problem: whenever we move the map,
    the tile set changes, so we issue a new retrieval. However for panning over
    wider areas this means retrievals get queued up and are executed
    sequentially. For tiles this is probably not that much of an issue, but for
    reads of larger areas this will take some time.

    I really do not want to introduce any sort of caching here: while caching
    could theoretically be speed improving (only fetch the tiles that are
    missing), in the multi-threaded version we saw that actually OOM are our
    biggest enemy. If we only had to cache pois it would not be that much of an
    issue, but we also need to cache named ways for road labels .... take up
    much more space.

    Best would probably be drawing the old data set if there is still an
    overlap of tiles and issue a single new request on background thread, then
    refresh when data has arrived. Plus cancel requests if tile set has changed
    again and is not being worked on yet.

    Ludwig

    On 2 January 2016 at 14:01, Emux [email protected] wrote:

    Yes that was the cause, I used the same map data store in renderer and
    label store like in old days.

    Playing with it, I see occasionally (without visible artifacts):

    org.mapsforge.map.reader.MapFile processWayDataBlockWARNING: invalid number of way nodes: 0

    Also the CPU usage continues to be quite high.

    —
    Reply to this email directly or view it on GitHub
    #741 (comment)
    .

  16. devemux86 commented on Jan 4, 2016

    @devemux86
    CollaboratorAuthor

    +1 for not resolving to cache again.

  17. added this to the 0.6.1 milestone on Feb 6, 2016
  18. devemux86 commented on Feb 6, 2016

    @devemux86
    CollaboratorAuthor

    @ludwigb we can close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions