-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
1. Replace indexof() with a hashmaps of loaded nodes. 2. Remove null and undefined from the members of relations.
000eb78
to
1d9a1a7
Compare
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Thanks. In that case I guess this is good. |
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. |
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. |
It shouldn't be necessary to redefine |
I've pushed openstreetmap/openstreetmap-website@70012ab as a quick fix but as you say we should find a way to do it better. |
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.
On flame graph it now looks like this:
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:
p.s. I'm not sure if you currently support new browsers, so I wrote code that does not use the new language features