yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

HighwaySegment::clin_mtx #253

Closed yakra closed 7 months ago

yakra commented 1 year ago

Carved out of #221:

Can the mutex be made more efficient?

Eliminating HighwaySegment::clin_mtx would get sizeof(HighwaySegment) down to 72 B, with potential to get even smaller. This could potentially speed up multiple tasks. Calls to add_clinched_by could be removed, instead calling TMBitset::add_index directly and locking/unlocking Route::mtx before/after, however's most efficient.

Overall pros & cons:

Route::store_traveled_segments could handle all the segments it needs to with one lock/unlock per call.

For concurrency augments, multiple successive segments are likely to have the same route due to being added in series by Route::store_traveled_segments. We could...


Or alternately, any of a number of more esoteric, incompletely-thought-out ideas to go mutex-free, involving 2D arrays, a separate threaded task for storing traveler with segments, etc. How about this?

This all comes with its own overhead, and may or may not be faster than whatever the fastest option above is.

For siteupdateST, skip this extra step and do things more or less as done now.


See also TravelMapping#151.

yakra commented 8 months ago
  • Con: More mutex contention; multiple travelers could be trying to add the same route even if not the same segment.

No noticeable difference. With so many routes in the system, the odds of 2+ travelers trying to add the same one at the same time are already vanishingly small. Performs better.

  • Con: Indirection.

No, scratch that. Same amount.

Still not enough contention to degrade performance. On the contrary, 1 mutex performs better than 2, whether it's smaller sizeof, just noise in the data, or whatever. So let's keep the code simple & save RAM.

t->clinched_segments.push_back(hs); yadda yadda

Leaving as is & accepting "the performance hit" is already a big performance boost. Plus, ConcAugThread & TravelerList::clinched_segments can be removed entirely. See TravelMapping#151 & 0b6711d on BiggaTomato.


Deleted branch on BiggaTomato

y253 @ e7dad8c, more locks/unlocks, fewer ternaries Benchmark. Does this perform better or worse?

Appears to perform every-so-slightly worse. Plus, parent had cleaner code.

Undid a few things from parent, 90f08a1: