Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up data processing for the data layer #43

Merged
merged 2 commits into from
Jan 5, 2025

Conversation

deevroman
Copy link
Contributor

@deevroman deevroman commented Jan 5, 2025

This PR doesn't fix the issue openstreetmap/openstreetmap-website#5466

It fixes a problem that will show up after it is fixed. But you can notice it now.

  1. Load a large area of ​​the map and wait for the /map method to finish loading
  2. You will have to wait a few seconds for the data to be processed before you see the warning.

On flame graph it now looks like this:

Снимок экрана 2025-01-05 в 18 53 35

https://share.firefox.dev/4a3ZXM9

The error lies in the quadratic complexity of the data processing algorithm.

Suppose you have loaded 3000 nodes and they are all in ways. (it’s easy to imagine buildings in a city or roads) Now the algorithm for each loaded node makes a traversal through all nodes of all ways and members in the relations. We get 3000*3000 ~ 9,000,000 operations!

The situation is also aggravated by the fact that the array of relation members keeps members that are not nodes and you still traversal them for each loaded point!

Total:

  1. Replace indexof() with a hashmaps of loaded nodes.
  2. Remove null and undefined from the members of relations.

p.s. I'm not sure if you currently support new browsers, so I wrote code that does not use the new language features

1. Replace indexof() with a hashmaps of loaded nodes.
2. Remove null and undefined from the members of relations.
@deevroman deevroman marked this pull request as ready for review January 5, 2025 16:16
for (var i = 0; i < relations.length; i++){
var relation = relations[i];
for (var j = 0; j < relation.members.length; j++) {
relationNodes[relation.members[j].id] = true
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this check that the member is actually a node? I realise the old code wasn't but that seems like it was a pre-existing bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the old and new code, this check is not necessary, since all members are not nodes are deleted https://github.com/deevroman/leaflet-osm/blob/d72b63467a891895877f8b121f7a9822ca7dcdf4/leaflet-osm.js#L309-L312

@tomhughes
Copy link
Member

Thanks. In that case I guess this is good.

@tomhughes tomhughes merged commit eb4fd05 into openstreetmap:master Jan 5, 2025
1 check passed
@mmd-osm
Copy link

mmd-osm commented Jan 7, 2025

It seems this change is causing some regressions: https://community.openstreetmap.org/t/transport-routes-are-displayed-without-stops-on-web-front-end/123949

For me, I also don't see bus stop nodes anymore when displaying bus route relations. I tested with commit 231177aa29c8c09135d9921956341a5f477cbb7b, where it was still working ok.

@AntonKhorev
Copy link
Contributor

@tomhughes
Copy link
Member

tomhughes commented Jan 7, 2025

Ugh. That should never have been allowed... It happened ages ago in openstreetmap/openstreetmap-website@a125ee8 but it should have been by adding a proper API here if necessary, not by inserting itself by the back door like that.

@AntonKhorev
Copy link
Contributor

It shouldn't be necessary to redefine interestingNode. All it currently does is it makes way nodes uninteresting. Let's say there's a road and some of its nodes are traffic lights or crossings. In the leaflet-osm version those are interesting, but osm-website makes them uninteresting when viewing just the way. There could be an option for L.OSM.DataLayer that does this instead. Currently it can't make this decision because it just shows whatever is in xml it's fed, it doesn't know if the client wanted to view a particular osm element.

@tomhughes
Copy link
Member

I've pushed openstreetmap/openstreetmap-website@70012ab as a quick fix but as you say we should find a way to do it better.

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.

4 participants