Skip to content

Ways deduplication performance improvement - #1629

Closed
Sublimis wants to merge 2 commits into
mapsforge:masterfrom
Sublimis:deduplicate-faster-final
Closed

Sublimis wants to merge 2 commits into
mapsforge:masterfrom
Sublimis:deduplicate-faster-final

Conversation

@Sublimis

@Sublimis Sublimis commented Jan 17, 2025 •

Copy link
Copy Markdown
Contributor
  • Deduplication performance was improved just for ways (pois not used).
  • Tested using three Germany_oam.osm.map files (just renamed, so exactly 3x duplication).
  • MapWorkerPool.DEBUG_TIMING = true, starting with München area on scale = 20km.
  • Tested on AWT only.

DEDUPLICATE (improved) took 2.3 seconds on average (±0.1).
RETURN_ALL took 3.1 seconds on average (±0.1).

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

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).

return readLabels(tile, false);
case DEDUPLICATE:
return readLabels(tile, true);
return readLabels(tile, true).deduplicate();

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 Why calling extra method?
We already pass deduplicate true, so it should happen in readLabels like the pois.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An additional method is required when you look at the algorithm. It doesn't really matter where exactly it gets called, as long as it's after all the reads and before returning the data to the caller. Now, using an extra parameter just for this is not productive. This parameter should go the way of the dodo once the algorithm is applied to POIs as well.

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 Then we should make the new method to work also on the pois and remove the parameter?

Now the method appears half implemented as the deduplicate parameter works only on the pois
and we need to call an extra method to do the previous work on the ways too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please let's do it in two steps. First to make this available to others for testing, and if all is good and accepted we'll implement pois as well. The functionality won't change anyway, and a new version is also not on the horizon :)

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 Sure, users can test the PR in their builds.

But in order to merge it, we need the API to be complete.
This is public API that now a method does half work.

@devemux86 devemux86 Jan 17, 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 I mean the public MapReadResult.add(MapReadResult other, boolean deduplicate)
that in the PR now deduplicates only the pois and needs and extra method for the ways.

Many users use the snapshots in their apps, so we cannot merge it in this state.
Unless the public add either works as before or we remove it and use the extra method?

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 Why not using the old API and deduplicate (with the new algorithm) the ways inside the add
like before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 Let's then wait a few hours/days until we get some feedback from folks at #1608, @mg4gh ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Sublimis Why not using the old API and deduplicate (with the new algorithm) the ways inside the add like before?

It feels more natural, less possibility of mistake, and it's usually better to be explicit about intentions in the code. Not a big deal though. The private MultiMapDataStore.read...() methods can keep their parameter (but why only boolean then, why not the dataPolicy?), however MapReadResult.add(MapReadResult, boolean) will definitely become obsolete.

@Sublimis Sublimis Jan 17, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Sublimis Why not using the old API and deduplicate (with the new algorithm) the ways inside the add like before?

Oh, you are talking about the MapReadResult.add()?? This method is called from the loop. While it could be done this way, it wouldn't be optimal, i.e. the resulting algorithm would be slower. It's much better to call the sort() once on a large collection, that many times on smaller collections increasing in size. Mathematics.

if (this.hashWays.add(way.hashCode())) {
this.ways.add(way);
}
}

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 New deduplicate should happen here like the pois.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Most definitely not. New deduplicate happens after all the reads, not during.

@devemux86 devemux86 Jan 17, 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 Please see above.


@Override
public boolean equals(Object o) {
return this == o;

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 Is it enough check for equals?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you mean?

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 The previous equals made many checks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, and this has been delegated to the compareTo() now. Please recall the flowchart: #1608 (comment)

} else if (!(obj instanceof Way)) {
return false;
public int hashCode() {
return System.identityHashCode(this);

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 Is this hash code for speed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes

@devemux86

devemux86 commented Jan 17, 2025 •

Copy link
Copy Markdown
Collaborator

I merged the pull request in branch issue_1629 for testing.

@Sublimis Sublimis closed this Jan 19, 2025
@Sublimis
Sublimis deleted the deduplicate-faster-final branch January 19, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants