Skip to content

subgraph gen: list -> set #217

Closed
Closed

Description

@yakra

Using sets instead of lists might provide a modest speed boost during subgraph generation

  • multisystem
  • multiregion
  • country
  • continent

Activity

  1. yakra commented on Jun 20, 2019

    @yakra
    ContributorAuthor

    Looks like this post is the product of a brainfart, and there's no checking for list/set membership involved.

  2. yakra commented on Jun 24, 2019

    @yakra
    ContributorAuthor

    Yes there is. That was the brainfart.

  3. reopened this on Jun 24, 2019
  4. self-assigned this
    on Jul 2, 2019
  5. yakra commented on Jul 5, 2019

    @yakra
    ContributorAuthor

    This appears to be another case of lists being more efficient than sets for containers with a very small number of elements, in terms of checking membership. Or at least, comparable.
    I may try sets again in the future, but in the meantime I've made some headway in wringing some more efficiency out of the existing code that utilizes lists.

    The strange part though is that I've seen code that should obviously be faster run a tiny bit slower in practice.
    I just had to do time trials for each tiny little tweak I made...
    I've been working with the C++ HighwayGraph::matching_collapsed_edges & HighwayGraph::matching_traveled_edges functions. Lots if ifs here, and a few breaks. Lots of branching. My theory is that subtle changes to the code are enough to affect the CPU's branch prediction algorithm such that the "faster" code ends up experiencing more pipeline stalls, and running slower in the end.
    I'm curious to see how the results would vary on different CPU architectures.
    I've Ivy Bridge, Sandy Bridge, Core, K10, and an AMD I-forget-what early dual-core at my disposal.

    Of course, the sensible thing to do would be to program as if branch prediction didn't matter, as if it didn't exist or worked perfectly. Different architectures will handle it differently.

  6. yakra commented on Nov 16, 2019

    @yakra
    ContributorAuthor

    All C++ talk here, no Python...

    I've seen code that should obviously be faster run a tiny bit slower in practice.
    Yadda yadda branch prediction yadda yadda different CPU architectures.

    Lol. No. I was working with small sample sets and seeing tiny fluctuations, smaller than my margin of error, and convincing myself I saw signal rather than noise.

    This appears to be another case of lists being more efficient than sets for containers with a very small number of elements, in terms of checking membership. Or at least, comparable.

    Sets will introduce a small performance penalty when inserting items, as the hashers check whether a given item is already in the set. We don't care about this part; we already know each region/system will be unique. The only benefit of using a set would be faster membership checks. With lists, we usually have one item or a small handful in them, meaning we can iterate through them in no time. (It also helps that we're comparing memory addresses, and not strings or anything more complicated.) With sets, we have additional overhead in finding where & how in a set structure a given item is stored. We only start to get into fairly large lists with the continent graphs, and while there does seem to be a small speed increase (15.8s vice 16.5s) barely becoming noticeable, it's negated by small increases in processing time across the other subgraph sets.

    Lists perform almost identically. Factor in a smaller RAM footprint (even though the effect is negligible) and it makes sense to use them.
    Part of the attraction in the conversion was tidying up the edge-matching code; I've done the equivalent with a new template function to test list membership. This and some other TINY tweaks to efficiency (not noticeable in practice) will be included with my changes for #233.

  7. yakra commented on Nov 16, 2019

    @yakra
    ContributorAuthor

    Dead code

    stash 7ee6d75dd1b18f225ca2773752540370c9f2a03a, branched from 49c527a

    GraphListEntry::regions std::list<Region*>* -> std::unordered_set<Region*>*
    GraphListEntry::systems std::list<HighwaySystem*>* -> std::unordered_set<HighwaySystem*>*
    ...with according changes everywhere we'd expect to get it to compile:

    • GraphListEntry ctor
    • GraphListEntry::tag(): regions->front()->foo -> (*regions->begin())->foo
    • graph_vector setup
      • graph_generation.cpp
      • 7 subgraph-category files
    • HGEdge label & line arguments

    And finally:

    • HighwayGraph.cpp: streamline & cleanup region & system matching for edges
      • same deal in HGEdge::label
      • similar to what made it into f33b12d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions