The International Simutrans Forum


Author Topic: Pull Request: Private Car Memory Compression  (Read 340 times)

0 Members and 1 Guest are viewing this topic.

Offline PJMack

  • *
  • Posts: 39
Pull Request: Private Car Memory Compression
« on: May 18, 2021, 02:52:28 AM »
Building upon the work the work of freddyhayward's pull request 343 (,20721.0.html), this pull request has the ways (weg_t) sharing the ordered_vector_tpl.  To do this, two static vectors of ordered_vectors are created, where the ordered_vector arrays are replaced with a handle (class private_car_route_map) containing the indexes of the vector, or in the case where there is only one element, that element.  This in itself would result in about 14% memory savings (assuming a worst case average of 4 two way roads per 1 four-way intersection where all such roads lead to more than two destinations in each direction), due to the reduction in overhead of storing empty ordered_vectors.

For additional memory saving, the vectors are where appropriate, assigned to the same index, or "linked", during the back-tracing stage of the routing procedure, reducing the redundancy.  Unfortunately, this modification comes with side effects.  In order to keep the add route procedure simple, roads can now have multiple routes to a single destination.  This is mitigated by having the cars choose one of the routes at random, which appears not to have a negative effect on traffic.  A commented out define statement (NO_PRIVATE_CAR_DESTINATION_LINKING) is placed in line 1973 of where uncommenting it would disable the linking, but still have the memory savings as per the paragraph above.

The save file is designed for both forwards and backwards compatibility, however backwards compatibility comes the the caveat that if a file is saved with this pull request and loaded without it, cars may end up lost until routes are recalculated.  Forwards compatibility does not have such caveat.

Offline jamespetts

  • Simutrans-Extended project coordinator
  • Administrator
  • *
  • Posts: 20920
  • Cake baker
    • Bridgewater-Brunel
  • Languages: EN
Re: Pull Request: Private Car Memory Compression
« Reply #1 on: May 23, 2021, 12:16:19 PM »
Thank you very much for this. After a little testing, this has now been incorporated.