Repository navigation
Open
Description
Vertex unique_name labels are stored:
- with waypoints
- with vertices
- as keys of
unique_waypointsdict/map - as keys of
verticesdict/map
How much memory do these use up?
Potential things to do:
- Convert
verticesmap to useWaypoint*s as keys rather thanunique_name
A. Reduced RAM footprint
B. Most likely faster lookup times unique_waypointsmap, we can keep: it's essentially used as a set to store unique point names (which we need), with associated colocation lists.
A. The only lookup we use is in inserting unique point names, like a set. Otherwise, after it's created we just iterate thru & pass the mapped values to the vertex ctor. No name->point list lookup. Thus no CPU time hit on that front.
B. What we can do is delete the singleton waypoint lists when finished constructing vertices.
C. Better yet, we don't even need lists. Just map a Waypoint* instead, and pass that to the vertex ctor.- For vertex objects, we can use a method rather than store
unique_name, as per Jim's note.
A. We can store a pointer to the string in theunique_waypoints(though I don't know how the equivalent might be done in Python) This lets us... - Delete unique names from
Waypoints when finished constructing vertices, worst case.
Do we: move unique_name creation into vertex construction, avoiding storing them in waypoints entirely?
- Doing so would require already having a set of unique coords/waypoints from which to construct vertices.
- Creating two sets (waypoints, then unique labels) may end up taking more time.
- Per-waypoint
unique_namecreation is skipped anyway for points already visited, so no big CPU hit here. May still be faster than creating two unordered_sets. - So, it may not make sense to reinvent the wheel...
- We can erase them from waypoints when done anyway, avoiding the problem of permanent RAM usage. The biggest downside here is having leftover empty string containers for each waypoint.
- To that end, maybe use a bool to track whether a unique name has been created & skip, and store unique names as
unique_waypointskeys only.
See also: #8
Activity
yakra commentedon Feb 1, 2019
11863199 bytes for unique names stored in waypoints, with null terminators
7359944 bytes for unique names stored in vertices, with null terminators
3 * 7,359,944 + 11,863,199 = 33,943,031.
I can save 26,583,087 B by going down to just one unique set.
Not counting whatever the
sizeofoverhead of std::string is.Not small potatoes, but not wicked big spuds eithah.
yakra commentedon Feb 1, 2019
sizeofstd::string is 32B.So, 3 * 24647560 + 37420959 = 111363639, with potential to save 86716079 B.
yakra commentedon Feb 6, 2019
Rethinking this...
We already have this, in the form of colocation lists. Construct vertices only for singleton points or those at the front of their colocation lists.
No need to create two sets. It may take a small amount more time to iterate thru all waypoints and check whether
!w->colocated || w == w->colocated.front()(C++) orw.colocated is none or w == w.colocated[0](Python) than to just iterate thru a known set, though this may be about as complicated as, or even a bit less then, creating a new set.Factor in dict/map lookups by Waypoint memory address rather than
unique_namestring, and we're most certainly winning.RAM will be a definite win, of course.
The path of less resistance, in terms of adapting the existing code, may be to keep unique name generation where it is in the HighwayGraph ctor, and pass a
constructedname to the HighwayGraphVertexInfo ctor, even if it's one more variable to pass (beyond the waypoint itself).OTOH, it may be nice to clean up & combine the canonical name & unique name routines into one. The HighwayGraphVertexInfo ctor seems the most sensible place to do this.
Maybe take the easy path as a temporary solution, then work out the cleaner option long-term.
yakra commentedon Feb 6, 2019
Vertex
unique_namelabels are stored, in chronological order:unique_waypointsdict/mapverticesdict/mapPotential things to do:
verticesmap to useWaypoint*s as keys rather thanunique_nameA. Reduced RAM footprint
B. Most likely faster lookup times
unique_waypointsmap.A. Iterate thru waypoints. Process singleton points, and points at the front of their colocation lists.
B. Store unique point names in a set.
C. Have HighwayGraphVertexInfo store, and its ctor receive, a single Waypoint rather than a (in the case of singleton points, ad hoc) colocation list.
Python: Vertex ctor gets a Waypoint, and still stores the full unique name string.
yakra commentedon Feb 7, 2019
Implemented in C++.
I ended up doing the "pointer into the set values" thing, probably out of still being a bit hung up on the idea of
unique_waypointsas a map, and needing to keep its values around. I could have just copied the string values themselves into the vertex objects, then deleted the set once done constructing vertices. It would be more intuitive, at least. (Speed, though? Lots of copy constructors would be involved... Maybe check it out in the future...)Luckily though, I can do this when I translate back to Python: Clear the set when done, and store unique names in vertex objects only. I still end up storing names in one place, not four, or even two.
yakra commentedon Feb 7, 2019
Python implementation: TravelMapping#190
Leaving this open to remind myself: