Repository navigation
Conversation
|
#2191 reduced parsing duration for my test dataset from 74s to 50s. With the changes of this PR we're down to about 38s. |
|
Fixes #2197 |
|
Do you know the underlying reason of the speed up? |
|
Most of the commits aim to reduce object creation and collection resizes which are both costly operations if they're often repeated. 0f376c6 tries to avoid additional lookups in the tree by passing through internal IDs from previous lookups. 16eb716 follows the OSM pbf spec as we only need to process one typ of object within a PrimitiveGroup. |
|
Is there any reason we keep ReaderNode.getEle() ? It's an ugly hack within setTag and isn't really used for routing. |
|
@karussell i removed the node skipping logic as it was quite an invasive change with little benefit. Also removed the elevation handling from the reader. |
|
@karussell any remarks? I'd like to get this merged as my other parsing related PRs are based on this. |
|
Could you please update this to latest master? |
|
@easbar done :) |
|
I did not look at the code yet, but I can confirm that this branch is faster and the numbers of nodes and edges stays the same. For germany-190101.osm.pbf I got: |
|
Thanks for testing 😃 #2205 should yield even better results while improving the readability of the code |
|
In general it is not clear which change is only for refactoring (or clean up) and which is to improve performance - can you move the unrelated changes into a separate PR?
The OSMReader is already a complicated mess ;) so I would try to avoid making it worse. And the "graphIndex" would add to this. Is this required for the speed up? I would really like to clean up and/or refactor OSMReader to make it faster, but readability and maintainability should be a higher priority now that reading PBFs is acceptable fast (and usually only a small part when CH or LM is involved).
Is this required for the speed up?
What is the reason you drop support for XML in #2205? And if this is done it should be done in a separate PR. In general smaller PRs can be merged faster :) |
Sure
Agreed 😅
See #2194 for more details. It was an attempt to reduce the number of lookups.
Fair point. I'm going to remove it.
Just a minor bugfix. I will move it to a separate PR.
The current implementation has to deal with both formats which leaves little room for optimizations and makes the code less readable. e.g osm2pgsql requires all imported pbfs to be sorted by type and id now. If we follow their requirement it could help us to improve #2194 See also our discussion in #2130 Anybody who wants to import XML files can still convert them with tools like osmconvert or osmium.
It's in fact it's already a separate branch but i haven't created PR yet. |
|
I ran master vs this branch a few more times: # master
2020-12-13 15:48:08.522 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:180s, pass2:280s, total:460s
2020-12-13 15:57:45.614 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:178s, pass2:283s, total:462s
2020-12-13 16:07:44.938 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:187s, pass2:296s, total:483s
2020-12-13 16:17:48.119 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:191s, pass2:292s, total:483s
2020-12-13 16:27:18.800 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:175s, pass2:279s, total:455s
2020-12-13 16:37:04.125 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:181s, pass2:287s, total:469s
2020-12-13 16:46:39.075 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:179s, pass2:280s, total:459s
2020-12-13 16:56:11.371 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:179s, pass2:276s, total:455s
2020-12-13 17:05:46.935 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:179s, pass2:281s, total:461s
2020-12-13 17:15:35.966 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:189s, pass2:282s, total:471s
2020-12-13 17:25:14.669 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:179s, pass2:281s, total:460s
2020-12-13 17:34:50.932 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:179s, pass2:278s, total:458s
# speedup_pbf
2020-12-13 09:48:14.702 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:170s, pass2:264s, total:434s
2020-12-13 09:57:27.834 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:170s, pass2:268s, total:438s
2020-12-13 10:06:51.245 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:179s, pass2:268s, total:447s
2020-12-13 10:16:08.205 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:173s, pass2:268s, total:441s
2020-12-13 10:25:36.795 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:177s, pass2:273s, total:451s
2020-12-13 10:34:49.561 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:170s, pass2:267s, total:437s
2020-12-13 10:44:07.813 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:174s, pass2:268s, total:442s
2020-12-13 10:53:29.824 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:172s, pass2:272s, total:445s
2020-12-13 11:02:47.947 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:172s, pass2:269s, total:441s
2020-12-13 11:12:28.436 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:182s, pass2:281s, total:463s
2020-12-13 11:21:45.686 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:171s, pass2:270s, total:441s
2020-12-13 11:31:05.948 [main] INFO com.graphhopper.reader.osm.OSMReader - time pass1:174s, pass2:270s, total:444sThe speedup seems like less than 10%? I was trying to check whether all the commits yield an improvement or if some are more crucial than others, but this wasn't very clear, because the differences were rather small. Did you run a similar experiment? This was germany-190101.osm.pbf (on a rather weak server) btw. |
I agree that having less different input (same for output) formats potentially leads to better maintainability and does not have many drawbacks especially when there are good tools to do the conversion. However, regarding pbf/xml OSM I wish we can keep xml support at least for tests, because binary pbf files are hard to track in git and harder to work with. Can we e.g. keep osmosis (its Java) as test dependency such that we can keep some small OSM xml files and convert them on the fly for tests (assuming our OSMReader only supports pbf in the future)? Or use osmium or some other tool and do the conversion as a pre-build step when running the tests. |
Git and binary files doesn't mix well but at least our test cases are tiny and usually added once without any further updates to their content.
If someone really wants to track down a bug and needs to examine the pbf: osmium cat -f osm map-bug432.osm.pbfI'm not sure if it's worth the hassle to do the conversion step for each unittest run if these files are rarely modified or even looked at. |
Why is it much hassle when the files are small? It should be quite fast? And like you say binary files do not work well with git, so in case we make an adjustment to one of these files it would be a hassle to convert them to xml and compare the different versions. |
|
If we go for this it would be easier to convert the pbfs of my other branch back to XML as i've already fixed a few issues like sorting etc. We also need to make sure that timestamps of the generated pbfs are correct as some unittests check them but i don't really know the reason for that. Maybe we can remove those checks. |
|
@karussell what's your take on this? |
|
I also prefer keeping XML for tests as a PBF file would require yet another step to decipher the graph (and changes are harder to track). And/or we create a possibility with ascii charts like suggested in #143 :) |
|
Can we merge this PR? I'm going to refactor my other branch and switch to on-the-fly conversion for the test files. |
I agree with @karussell here that it is still hard to see what changes are meant to be speed ups and which ones are mostly there to clean up the code. Also I fully agree that cleaning up should be the priority. I 'accidentally' got familiar with the OSM reading code because of another bug I am investigating (#1984 ) so I had a look at this PR again. I see the following issues:
Regarding the changes in this PR I see three main things that were changed:
|
|
Once we come to an agreement about what should be done we can probably also just cherry pick some of this PR's commits as they already nicely separate the different changes. |
|
|
||
| // Build a new bound object which corresponds to the header. | ||
| /* | ||
| Bound bound; | ||
| if (header.hasBbox()) { | ||
| HeaderBBox bbox = header.getBbox(); | ||
| bound = new Bound(bbox.getRight() * COORDINATE_SCALING_FACTOR, bbox.getLeft() * COORDINATE_SCALING_FACTOR, | ||
| bbox.getTop() * COORDINATE_SCALING_FACTOR, bbox.getBottom() * COORDINATE_SCALING_FACTOR, | ||
| header.getSource()); | ||
| } else { | ||
| bound = new Bound(header.getSource()); | ||
| } | ||
|
|
||
| // Add the bound object to the results. | ||
| decodedEntities.add(new BoundContainer(bound)); | ||
| */ |
I think we should be able to easily use VCS friendly .osm.xml files for testing. On the other hand I do not see many benefits in testing with OSM-like data except for testing the code that does the OSM import and some end-to-end tests. For everything else testing via the Java/GraphHopper API seems a lot more useful. Therefore I do not really see a use-case for these ascii charts ;) |
|
Focusing on better readability first seems like a good idea. My biggest gripe with the existing XML files is that most of them violate the specification one way or another. Fixing all these issues in order to able to convert them on-the-fly is going to take a while. |
What kind of specifications are violated? Can we address these issues first without removing XML support yet? |
|
Btw I see you put in a lot of work into this OSM parsing code. What is the overall goal of this? Is this mostly about speeding things up or removing the osmosis dependency? Do you also have functional improvements or extensions n mind? |
I tried to do the conversion using Osmosis v0.6 XML Reader and OsmosisSerializer. It got various errors about missing timestamp and version tags.
Speed and readability. |
|
Osmosis 0.6? Isn't 0.48 the latest release: https://github.com/openstreetmap/osmosis/releases/latest? You probably mean OSM API version 0.6 and this is in fact not supported by e.g. latest versions of Osmosis and JOSM. I had a similar problem when I tried opening one of the test xml files in JOSM (it required the version tag). The last osmosis version that supported OSM v0.5 was 0.35 and it has a migrate command to convert from v0.5 to v0.6: https://wiki.openstreetmap.org/wiki/Osmosis/Detailed_Usage_0.35#--migrate --> #2223 |
That's exactly the problem i'm facing. |
|
I'll close this issue here. @otbutz let me explain :) Our first step should be to make OSMReader simpler - it is a mess :) ! See https://github.com/graphhopper/graphhopper/commits/osm_reader_rewrite for an experimental branch that also includes some minor ideas from here I think. But even this rewrite is not yet possible as we first need to get the correct bigger picture. And so we e.g. need to think about how to handle the node tags (see my branch And after this is done we can then try to make the (new) OSMReader faster again. Especially due to your contribution from #2191 I think performance is now less of a concern and we really need to focus on maintainability. |
I wholeheartedly agree 😉 |
This should speedup pbf parsing by about 10%