|
On a shard, an incremental routing table refresh can start while there are still a lot of chunks that need to be persisted from a previous refresh. When this happens, almost the whole chunks vector is unnecessarily scanned in order to find the new entries.
Example
- 1M chunks already seen by previous refresh are being persisted
- Refresh discovers 1 new chunk
- 1M elements will be scanned here
Solution
Since collAndChunks.changedChunks is a sorted vector, we could simply invert the direction of the loop and scan in decreasing order starting from collAndChunks.changedChunks.end() . If we consider that it is very improbable for a lot of new chunks to be discovered, this will be even more efficient than performing a binary search on the vector.
|