You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
stash 7ee6d75dd1b18f225ca2773752540370c9f2a03a, branched from 49c527a
GraphListEntry::regionsstd::list<Region*>* -> std::unordered_set<Region*>* GraphListEntry::systemsstd::list<HighwaySystem*>* -> std::unordered_set<HighwaySystem*>*
...with according changes everywhere we'd expect to get it to compile:
Activity
yakra commentedon Jun 20, 2019
Looks like this post is the product of a brainfart, and there's no checking for list/set membership involved.
yakra commentedon Jun 24, 2019
Yes there is. That was the brainfart.
yakra commentedon Jul 5, 2019
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_edgesfunctions. 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.
yakra commentedon Nov 16, 2019
All C++ talk here, no Python...
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.
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.
yakra commentedon Nov 16, 2019
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:
regions->front()->foo->(*regions->begin())->fooAnd finally: