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

Fix inefficient code related to #1553 #1591

Closed
cka-y opened this issue Sep 29, 2023 · 0 comments · Fixed by #1592
Closed

Fix inefficient code related to #1553 #1591

cka-y opened this issue Sep 29, 2023 · 0 comments · Fixed by #1592
Assignees

Comments

@cka-y
Copy link
Contributor

cka-y commented Sep 29, 2023

Looking at #1553, there is definitely so inefficient code in there.

For example:

    List<String> uniqueShapeIds =
        shapeTable.getEntities().stream()
            .map(GtfsShape::shapeId)
            .distinct()
            .collect(Collectors.toList());

This is iterating over every line in shapes.txt, when the set of unique shape ids is already available via GtfsShapeTableContainer#byShapeIdMap().

Then, the worst offender:

    uniqueShapeIds.forEach(
        shapeId -> {
          double maxShapeDist =
              shapeTable.getEntities().stream()
                  .filter(s -> s.shapeId().equals(shapeId))
                  .mapToDouble(GtfsShape::shapeDistTraveled)
                  .max()
                  .orElse(Double.NEGATIVE_INFINITY);

For each shape ids, we are again looping over every entry in shapes.txt to find matching shape points. This is where the NxM blow-up and slow-down is likely coming from. Again GtfsShapeTableContainer#byShapeIdMap() already has all the shape points grouped by shape id and should be used directly.

I'd also point out that the shape points and stop points below should both probably be filtered by hasShapeDistTraveled as well.

Originally posted by @bdferris-v2 in #1587 (comment)

@cka-y cka-y self-assigned this Sep 29, 2023
@cka-y cka-y mentioned this issue Sep 29, 2023
4 tasks
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 a pull request may close this issue.

1 participant