Make turn restrictions faster and thread-safe by moving them into StreetEdge#3899
Conversation
a3c525f to
c3fe836
Compare
Co-authored-by: Hannes Junnila <hannes.junnila@gmail.com>
Co-authored-by: Thomas Gran <t2gran@gmail.com>
4d2e0f0 to
0159fe5
Compare
0159fe5 to
5831ccc
Compare
hannesj
left a comment
There was a problem hiding this comment.
This seems to reduce the time spent in StreetRouter from 19.5 ms to 18.0 ms in the SpeedTest.
kryo_set_serialization.diff can be used to fix the serialization issue, with the java.util.ImmutableCollections Set
4be5bd3 to
c955e7e
Compare
e823cba to
d17e9ba
Compare
| public final TurnRestrictionType type; | ||
| public final StreetEdge from; | ||
| public final StreetEdge to; | ||
| public final RepeatingTimePeriod time; | ||
| public final TraverseModeSet modes; | ||
|
|
|
There is probably a long discussion on the use of Set vs List here. And I would agree that we sometimes want to use Set just to communicate the "unique"-ness of the elements. But, Set have a bigger overhead to then (maybe not for 1 and 2 elements), but at least mentally - so wen memory footprint and performance is high priority I prefer to use list, and just make sure the construction of them enforce the "unique"-ness constraint. Also, in this case there is no need to expose the collection type outside the StreetEdge. |
4e40034 to
63478d9
Compare
I'm happy to go along with this suggestion. |
|
🙏 |
Summary
It moves the turn restrictions form a global map to the individual
StreetEdgeinstances.This has several advantages:
StreetEdgethread-safe than one onGraphThread safety
This is actually a bit trickier than one might suspect since we have the following constraints:
For these reasons I've chosen the following design:
Issue
Relates to #3884 but not confirmed that it solves the issue.
Unit tests
Unit tests adjusted
Code style
yes
Documentation
Plenty of Javadoc added.