Skip to content

Ways and POIs deduplication performance and correctness improvement - #1635

Merged
devemux86 merged 5 commits into
mapsforge:masterfrom
Sublimis:deduplicate-faster-final
Jan 23, 2025
Merged

devemux86 merged 5 commits into
mapsforge:masterfrom
Sublimis:deduplicate-faster-final

Conversation

@Sublimis

@Sublimis Sublimis commented Jan 19, 2025 •

Copy link
Copy Markdown
Contributor

Deduplication performance and correctness improvement for ways and POIs.

  • Tested using three Germany_oam.osm.map files (just renamed, so exactly 3x duplication), without POIs.
  • MapWorkerPool.DEBUG_TIMING = true, starting with München area on scale = 20km.
  • Tested on AWT only.

Results:

  • DEDUPLICATE (improved) took 2.3 seconds on average (±0.1) to draw the map.
  • RETURN_ALL took 3.1 seconds on average (±0.1) to draw the map.

The performance of the legacy DEDUPLICATE method was tested later and found to be comparable to RETURN_ALL, thus significantly slower (unsurprisingly).

An additional advantage of the new deduplication approach is correctness: This algorithm does not suffer from hash collisions, unlike the previous one. This becomes increasingly important as maps get bigger.

Android wasn't tested, but the relative results could be even better there, given that mobile devices have weaker GPUs. Not sure, though, maybe someone could do some testing on Android.

This makes the DEDUPLICATE method a good candidate for the recommended and default behavior, possibly mitigating the need for map bounding polygons (#1608).

}

private MapReadResult readLabels(Tile tile, boolean deduplicate) {
private MapReadResult readLabelsPriv(Tile tile) {

@devemux86 devemux86 Jan 20, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sublimis Let's use a more understandable name in these methods.

Better a different name like processLabels, searchLabels, doReadLabels, etc.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks, it looks good. 👍

I merged it in branch issue_1635 if anyone wants to test it.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis We can merge this, but the method names must be improved (see #1635 (comment)).

@Sublimis

Copy link
Copy Markdown
Contributor Author

@devemux86 Do you mind if we change private to protected in MultiMapDataStore while at it? It somehow doesn't seem natural to have privates in an open source library, esp. for such an ubiquitous class. Also avoids possible future requests like #1512, "can you please make this non-private, we want to extend"...

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis No problem, although it introduces the problem that then we cannot easily rename / remove them without breaking user apps.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks for the changes. Is it ready?

Should we also change the DataPolicy in the MultiMapLowResWorld sample?

@Sublimis

Copy link
Copy Markdown
Contributor Author

Question, since this hasn't been merged yet: Does the order of the elements in the MapReadResult matter, i.e. does the order have to be the same before and after deduplication?
Iff not, then additional improvements can be made here, including bringing back the original hashCode() and equals(), for example, as well as not creating additional list structures.

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis Thanks for the changes. Is it ready?

Should we also change the DataPolicy in the MultiMapLowResWorld sample?

Maybe, but since it's just a small world map with no expected duplicates, it's not that important. But it can be done for consistency, of course.

@Sublimis

Copy link
Copy Markdown
Contributor Author

Question, since this hasn't been merged yet: Does the order of the elements in the MapReadResult matter, i.e. does the order have to be the same before and after deduplication? Iff not, then additional improvements can be made here, including bringing back the original hashCode() and equals(), for example, as well as not creating additional list structures.

It's not a big deal because these hashCode()/equals() are not currently used, but just in case they are needed in the future.

@devemux86

Copy link
Copy Markdown
Collaborator

Maybe, but since it's just a small world map with no expected duplicates, it's not that important. But it can be done for consistency, of course.

@Sublimis Let's change also this, as we currently recommend the deduplicate as default?

@devemux86

Copy link
Copy Markdown
Collaborator

Does the order of the elements in the MapReadResult matter, i.e. does the order have to be the same before and after deduplication?

@Sublimis Was it like this before?

@Sublimis

Copy link
Copy Markdown
Contributor Author

Does the order of the elements in the MapReadResult matter, i.e. does the order have to be the same before and after deduplication?

@Sublimis Was it like this before?

Yes, but in the previous implementation this was done in a "passive" way so to speak, i.e. it was just a byproduct of the condition "should we add this element to the list or not", there was no explicit intent that we could now refer to.

The current implementation intentionally preserves the order, but this is done only for safety reasons, not because we are 100% sure that the order should be preserved...

Not sure, but the order in MapReadResult appears to be the same as the order given in the map file. This then boils down to the question: Is the order of elements in the map file expected to affect the order in which elements are displayed on the screen?

@devemux86

Copy link
Copy Markdown
Collaborator

Is the order of elements in the map file expected to affect the order in which elements are displayed on the screen?

@Sublimis The rendering depends on the render theme. So it should not matter?
If performance improvements can be made because of this, we better do them.

Although better to test all of these to be sure? 🙂

@Sublimis

Copy link
Copy Markdown
Contributor Author

Okay, let's try it now. The performance probably won't be much better, maybe a few percent at most, it's more about making hashCode() and equals() future-proof if possible.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Do you mean it's ready or more changes are needed?

@Sublimis

Sublimis commented Jan 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Good news! The order of the elements doesn't seem to matter at all, and even the code is notably more efficient, by more than 10% in total execution time until the map is drawn.
We thought we'd just include those improvements here?

@devemux86

Copy link
Copy Markdown
Collaborator

We thought we'd just include those improvements here?

@Sublimis Let's include them here.

@Sublimis

Copy link
Copy Markdown
Contributor Author

You can leave this percolating here for another day or two AFAIC. The testers are asleep. 🆗

@devemux86

Copy link
Copy Markdown
Collaborator

I updated branch issue_1635 if anyone wants to test it.

@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Is it ready, should we merge it?

@Sublimis

Copy link
Copy Markdown
Contributor Author

@Sublimis Is it ready, should we merge it?

Yup, ready 👍

@devemux86 devemux86 added this to the 0.24.0 milestone Jan 23, 2025
@devemux86
devemux86 merged commit b0a4a45 into mapsforge:master Jan 23, 2025
@devemux86

Copy link
Copy Markdown
Collaborator

@Sublimis Thanks, nice work!

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.

2 participants